UVA-814 邮件传输代理的交互 题解答案代码 算法竞赛入门经典第二版 code • 2022-4-6 • C • 阅读 46 GitHub - jzplp/aoapc-UVA-Answer: 算法竞赛入门经典 例题和习题答案 刘汝佳 第二版 AC代码 #include #include #include #include #include using namespace std; void getName(string iden, string &name, string &mta) { int n = iden.find('@'); name = iden.substr(0, n); mta = iden.substr(n+1); } int main() { string s, mta, send, name, reci, data; string data_space = " "; string send_name, send_mta, reci_name, reci_mta; set se; bool flag; int n, i, j; while(cin >> s && s != "*") { cin >> mta; cin >> n; while(n--) { cin >> name; se.insert(name + "@" + mta); } } while(cin >> send && send != "*") { getName(send, send_name, send_mta); vector mta_v; map > reci_mp; set reci_se; while(cin >> reci && reci != "*") { if(reci_se.count(reci)) continue; reci_se.insert(reci); getName(reci, reci_name, reci_mta); if(!reci_mp.count(reci_mta)) { mta_v.push_back(reci_mta); reci_mp[reci_mta] = vector(); } reci_mp[reci_mta].push_back(reci); } getline(cin, s); data = ""; while(getline(cin, s) && s != "*") { data += data_space + s + "\n"; } for(i = 0; i < mta_v.size(); ++i) { cout << "Connection between " << send_mta << " and " << mta_v[i] << endl; cout << data_space << "HELO " << send_mta << endl; cout << data_space << 250 << endl; cout << data_space << "MAIL FROM:<" << send << ">" << endl; cout << data_space << 250 << endl; flag = false; for(j = 0; j < reci_mp[mta_v[i]].size(); ++j) { cout << data_space << "RCPT TO:<" << reci_mp[mta_v[i]][j] << ">" << endl; if(se.count(reci_mp[mta_v[i]][j])) { flag = true; cout << data_space << 250 << endl; } else { cout << data_space << 550 << endl; } } if(flag) { cout << data_space << "DATA" << endl; cout << data_space << 354 << endl; cout << data; cout << data_space << "." << endl; cout << data_space << 250 << endl; } cout << data_space << "QUIT" << endl; cout << data_space << 221 << endl; } } return 0; } 欢迎分享,转载请注明来源:内存溢出原文地址: http://outofmemory.cn/langs/565082.html 赞 (0) 打赏 微信扫一扫 支付宝扫一扫 code 管理员组 0 0 生成海报 51单片机基础之流水灯(一) 上一篇 2022-04-06 C++: 对象的初始化和清理(构造函数与析构函数) 下一篇 2022-04-06 发表评论 请登录后评论... 登录后才能评论 提交 评论列表(0条)
评论列表(0条)