本文主要是介绍例题5-11 邮件传输代理的交互(The Letter Carrier's Rounds,ACM/ICPC World Finals 1999,UVa814),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原题链接:https://vjudge.net/problem/UVA-814
分类:STL综合
备注:字符串以及STL容器的综合运用
前言:uDebug AndyRoswellD的数据没过,但是我没看懂他的输出的逻辑,难道有多个传输者?题目没这么写啊,好歹还是AC了。个人认为是他上传的数据有误。
代码如下:
#include<iostream>
#include<sstream>
#include<string>
#include<map>
#include<set>
#include<vector>
using namespace std;
map<string, set<string> >person;
set<string>adress;
void output(string s, vector<string>message) {stringstream ss(s); string sender, senddress;ss >> sender;int pos = sender.find('@');senddress = sender.substr(pos + 1);string tmp, dr;vector<string>recdress;vector<string>recpt;map<string, set<string> >match;while (ss >> tmp) {pos = tmp.find('@');dr = tmp.substr(pos + 1);if (!match.count(dr))recdress.push_back(dr);if (!match[dr].count(tmp)) {recpt.push_back(tmp);match[dr].insert(tmp);}}for (int i = 0; i < recdress.size(); i++) {cout << "Connection between " << senddress << " and " << recdress[i] << "\n";cout << " HELO " << senddress << "\n 250\n MAIL FROM:<" << sender << ">\n 250\n";int flag = 0;for (int j = 0; j < recpt.size(); j++) {if (match[recdress[i]].count(recpt[j])) {cout << " RCPT TO:<" << recpt[j] << ">\n";pos = recpt[j].find('@');string tmp2 = recpt[j].substr(0, pos);if (person[recdress[i]].count(tmp2)) {cout << " 250\n";flag = 1;}else cout << " 550\n";}}if (flag) {cout << " DATA\n 354\n";for (int k = 0; k < message.size(); k++)cout << " " << message[k] << "\n";cout << " .\n 250\n";}cout << " QUIT\n 221\n";}
}
int main(void){int n;string s, pepo;while (cin >> s){if (s[0] == '*')break;cin >> s;adress.insert(s);cin >> n;while (n--) {cin >> pepo;person[s].insert(pepo);}}getchar();while (getline(cin,s)){if (s[0] == '*')break;string mess;cin >> mess;getchar();vector<string>message;while (getline(cin, mess)){if (mess[0] == '*')break;message.push_back(mess);}output(s, message);}return 0;
}
这篇关于例题5-11 邮件传输代理的交互(The Letter Carrier's Rounds,ACM/ICPC World Finals 1999,UVa814)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!