算典05_例题_11_UVA-814
2017-04-20 15:11
281 查看
The Letter Carrier’s Rounds
题意
本题的任务为模拟发送邮件时MTA(邮件传输代理)之间的交互。所谓MTA,就是email地址格式user@mtaname的“后面部分”。当某人从user1@mta1发送给另一个人user2@mta2时,这两个MTA将会通信。如果两个收件人属于同一个MTA,发送者的MTA只需与这个MTA通信一次就可以把邮件发送给这两个人。题解
mapset
看代码
#include <algorithm> #include <iostream> #include <sstream> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <cstring> #include <cstdio> #include <cmath> #define met(a, b) memset(a, b, sizeof(a)); #define IN freopen("in.txt", "r", stdin); using namespace std; typedef long long LL; const int maxn = 1e6 + 5; const int INF = (1 << 31) - 1; string s, t, user1, mta1, user2, mta2; int k; set<string> addr; void solve(const string& s, string& user, string& mta) { int k = s.find('@'); user = s.substr(0,k); mta = s.substr(k+1); } int main() { #ifdef _LOCAL IN; #endif // _LOCAL //insert while(cin >> s && s != "*") { cin >> s >> k; while(k--) {cin >> t; addr.insert(t + "@" + s); } } while(cin >> s && s != "*") { solve(s, user1, mta1); vector<string> mta; map<string, vector<string> > dest; set<string> vis; while(cin >> t && t != "*") { solve(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[0] != '*') 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 << "\n"; cout << " 250\n"; cout << " MAIL FROM:<" << s << ">\n"; cout << " 250\n"; bool ok = false; for(int i = 0; i < users.size(); i++) { cout << " RCPT TO:<" << users[i] << ">\n"; if(addr.count(users[i])) { ok = true; cout << " 250\n"; } else cout << " 550\n"; } if(ok) { cout << " DATA\n"; cout << " 354\n"; cout << data; cout << " .\n"; cout << " 250\n"; } cout << " QUIT\n"; cout << " 221\n"; } } return 0; }
相关文章推荐
- 例题5-11 UVA 814 The Letter Carrier’s Rounds邮件传输代理的交互
- 例题6-11 UVa297 Quadtrees(四分树)
- 例题11-2 苗条的生成树 UVa1395 Kruskal算法样例(基于并查集,which is almost like set)
- 算典05_例题_07_UVA-136
- UVa #12661 Funny Car Racing (例题11-11)
- 【例题 6-11 UVA-297】Quadtrees
- 11.3.4 例题11-5 UVA 247 Audiophobia(两点间最大权最小_floyd()变形)
- Uva297 Quadtrees【递归建四分树】【例题6-11】
- 算典05_例题_08_UVA-400
- 11.3.4 例题11-6 UVA 658 It's not a Bug, it's a Feature! ()
- 紫书 例题 11-4 电话圈 UVa247 Floyd传递闭包
- 【例题 8-11 UVA-10954】Add All
- 算典04_例题_05_UVA-512
- 例题9-11 UVa1331 Minimax Triangulation(DP:最优三角剖分)
- UVa #1349 Optimal Bus Route Design (例题11-10)
- UVa #10954 Add All (例题8-11)
- 算典05_例题_10_UVA-207
- 例题6-11 四分树(Quadtrees, UVa 297)
- 例题11-4 电话圈 uva247
- 算典05_例题_02_UVA-101