算典05_例题_11_UVA-814
来源:互联网 发布:对人工智能的看法400字 编辑:程序博客网 时间:2024/05/23 00:08
The Letter Carrier’s Rounds
题意
本题的任务为模拟发送邮件时MTA(邮件传输代理)之间的交互。所谓MTA,就是email地址格式user@mtaname的“后面部分”。当某人从user1@mta1发送给另一个人user2@mta2时,这两个MTA将会通信。如果两个收件人属于同一个MTA,发送者的MTA只需与这个MTA通信一次就可以把邮件发送给这两个人。
题解
map
set
看代码
#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;}
0 0
- 算典05_例题_11_UVA-814
- 算典03_习题_11_UVA-1588
- 算典05_例题_01_UVA-10474
- 算典05_例题_02_UVA-101
- 算典05_例题_03_UVA-10815
- 算典05_例题_04_UVA-156
- 算典05_例题_05_UVA-12096
- 算典05_例题_06_UVA-540
- 算典05_例题_07_UVA-136
- 算典05_例题_08_UVA-400
- 算典05_例题_09_UVA-1592
- 算典05_例题_10_UVA-207
- 算典05_例题_12_UVA-221
- 算典03_例题_01_Uva-272
- 算典03_例题_02_Poj-2538
- 算典03_例题_03_HDU-1318
- 算典03_例题_04_Uva-340
- 算典03_例题_05_Uva-1583
- Python 标准库简介concurrent.futures
- oracle命令杂记
- 如何定位死循环或高CPU使用率(linux)
- 编译安装hadoop
- 鼠标滚轮事件
- 算典05_例题_11_UVA-814
- 开源硬件介绍
- linux下mysql开启远程访问权限及防火墙开放3306端口
- android 显示全部Log信息。
- iOS状态栏设置样式
- POJ 2533 Longest Ordered Subsequence 二分查找(LIS nlogn算法)
- 恩格尔系数
- eclipse常用快捷键总结
- MySQL5.6配置文件详解