• UVa 814邮件传输代理的交互


    好吧,终于知道原来string有这么多用法,map可以通过vector来映射多个数

     1 #include <iostream>  
     3 #include <string>  
     4 #include <set>  
     5 #include <map>  
     6 #include <vector>  
     8 using namespace std;  
     9   
    10 void parse_address(string const s, string& user, string& mta) {  
    11     int t = s.find('@');  
    12     user = s.substr(0, t);  
    13     mta = s.substr(t + 1);  
    14 }  
    15   
    16 int main() {  
    20     int k;  
    21     string s, t, user1, user2, mta1, mta2;  
    22     set<string> addr;  
    23   
    24     while(cin >> s&& s[0] != '*') {  
    25         cin >> t >> k;  
    26         while(k--) {cin >> s; addr.insert(s + '@' + t);}  
    27     }  
    28   
    29     while(cin >> s&& s[0] != '*') {  
    30         parse_address(s, user1, mta1);  
    31   
    32         vector<string> mta;  
    33         map<string, vector<string> > dest;  
    34         set<string> vis;  
    35   
    36         while(cin >> t&& t[0] != '*') {  
    37             if(vis.count(t)) continue;  
    38             vis.insert(t);  
    39             parse_address(t, user2, mta2);  
    40             if(!dest.count(mta2)) {mta.push_back(mta2); dest[mta2] = vector<string>();}  
    41             dest[mta2].push_back(t);  
    42         }  
    43         getline(cin, t);  
    44   
    45         string data;  
    46         while(getline(cin, t)&& t[0] != '*') data += "     " + t + "
    ";  
    47   
    48         for(int i = 0; i < mta.size(); i++) {  
    49             mta2 = mta[i];  
    50             vector<string> users = dest[mta2];  
    51             cout << "Connection between " << mta1 << " and " << mta2 << "
    ";  
    52             cout << "     HELO "<< mta1 << "
    ";  
    53             cout << "     250
    ";  
    54             cout << "     MAIL FROM:<" << user1 << "@" << mta1 << ">
    ";  
    55             cout << "     250
    ";  
    56             bool ok = false;  
    57             for(int i = 0; i < users.size(); i++) {  
    58                 cout << "     RCPT TO:<" << users[i] << ">
    ";  
    59                 if(addr.count(users[i])) {ok = true; cout << "     250
    "; }  
    60                 else cout << "     550
    ";  
    61             }  
    62             if(ok) {  
    63                 cout << "     DATA
         354
    ";  
    64                 cout << data;  
    65                 cout << "     .
    " << "     250
    ";  
    66             }  
    67             cout << "     QUIT
         221
    ";  
    68         }  
    69     }  
    70   
    71     return 0;  
    72 }  
  • 相关阅读:
    MySQL--lsblk命令查看块设备
    MySQL--linux IO调度算法
    一致性哈希
    MySQL--查询表统计信息
    MySQL--区分表名大小写
    MySQL--Online DDL
    MySQL--MODIFY COLUMN和ALTER COLUMN
    MySQL--修改表字段
    MySQL--增加或修改列注释
    鼠标事件
  • 原文地址:https://www.cnblogs.com/zyb993963526/p/6091190.html
Copyright © 2020-2023  润新知