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 + "\n"; 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 << "\n"; 52 cout << " HELO "<< mta1 << "\n"; 53 cout << " 250\n"; 54 cout << " MAIL FROM:<" << user1 << "@" << mta1 << ">\n"; 55 cout << " 250\n"; 56 bool ok = false; 57 for(int i = 0; i < users.size(); i++) { 58 cout << " RCPT TO:<" << users[i] << ">\n"; 59 if(addr.count(users[i])) {ok = true; cout << " 250\n"; } 60 else cout << " 550\n"; 61 } 62 if(ok) { 63 cout << " DATA\n 354\n"; 64 cout << data; 65 cout << " .\n" << " 250\n"; 66 } 67 cout << " QUIT\n 221\n"; 68 } 69 } 70 71 return 0; 72 }