UVA 814 MTA 模拟
2017-04-18 17:30
169 查看
#include<iostream> #include<vector> #include<map> #include<set> #include<string> //#define LOCAL #include<cstdio> using namespace std; void getInformation(string& ss, string user, string & mat) { int k = ss.find('@'); user = ss.substr(0, k); mat = ss.substr(k+1); } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // LOCAL int n; string s, t, s1, s2, mta1, mta2, user1, user2; // 对MAT进行整理 , 变成 姓名@地址的形式. set<string> adds; while(cin >> s1 && s1 != "*"){ cin >> s >> n; while(n--){ cin >> s2; adds.insert(s2 + "@" + s); } } // 处理发件人的信息, 把姓名和地址分开 while(cin >> s && s != "*") { getInformation(s, user1, mta1); // 关于字符串的处理 vector<string> mta; map<string, vector<string> > dest; set<string> vis; while(cin >> t && t != "*") { getInformation(t, user2, mta2); if(vis.count(t)) continue; // 重复的收件人, 直接跳过后续工作 vis.insert(t); if(!dest.count(mta2)) { mta.push_back(mta2); dest[mta2] = vector<string>();} dest[mta2].push_back(t); } getline(cin, t); // 正文的处理,整合成一句话 string data; while(getline(cin, t) && t != "*") data += " " + t + "\n"; // 对信息内容的处理 for(int i = 0; i < mta.size(); i++) { string mta2 = mta[i]; vector<string> users = dest[mta2]; cout << "Connection between " << mta1 << " and " << mta2 << endl; cout << " HELO " << mta1 <<endl << " 250" <<endl; cout << " MAIL FROM:<" << s << ">" << endl << " 250" <<endl; bool ok = false; for(int i = 0; i < users.size(); i++){ cout << " RCPT TO:<" << users[i] << ">" <<endl ; if(adds.count(users[i])) {ok = true; cout << " 250\n";} else cout << " 550\n"; } if(ok) { cout << " DATA\n"; cout << " 354\n"; cout << data; cout << " .\n" <<" 250\n"; } cout << " QUIT\n" << " 221\n"; } } return 0; }
相关文章推荐
- UVa 814 - The Letter Carrier's Rounds(模拟)
- UVA ~ 814 ~ The Letter Carrier's Rounds (模拟 + map + set + vector)
- UVA ~ 1597 ~ Searching the Web (模拟,map+bitset)
- UValive 7269 (模拟)
- UVA10978 Let's Play Magic!【模拟】
- uva 1352 LA3401 - Colored Cubes(模拟,4级)
- uva 227--模拟
- Problem on Group Trip UVALive - 7219 (模拟+优先队列处理)
- UVA 10878-Decode the tape(模拟)
- UVa 101 The Blocks Problem 【STL】【vector】【模拟】
- UVA 12657(双向链表模拟)
- UVA 12504(模拟)
- uva - 140 - Bandwidth(模拟 + 下一个排列 + 图)
- UVA 11039 模拟
- UVa 202 Repeating Decimals【模拟】
- 【基础练习】【模拟】Uva133 - The Dole Queue题解
- UVA 127 - "Accordian" Patience (模拟)
- (1.1.6)UVA 10978 Let's Play Magic!(直叙式模拟)
- 紫书章四 Spreadsheet Tracking UVA - 512(单元格去哪了,模拟结果更简单))
- 紫书章四习题一 xiangqi uva 1589(模拟)