814:The Letter Carrier's Rounds
The Letter Carrier's Rounds
注意可能有重复的收件人。
version 1(20ms):
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 150,maxlen = 80;
char mes[maxlen];
map<string,string>mta;
string tf[maxn],tm[maxn];
void readmes(){int i = 0;getchar();for(;;){char c = getchar();if(c != '*'){mes[i++] = c;if(c == '\n'){int t = 5;while(t--) mes[i++] = ' ';}}else break;}mes[i] = 0;
}
int main(){int n;string a,b,t;while(cin>>t && t[0] != '*'){cin>>a>>n;while(n--){cin>>b;mta[b] = a;}}string uf,um;while(cin>>t && t[0] != '*'){int p = t.find('@',0);uf = t.substr(0,p);um = t.substr(p+1,t.length()-p+1);int cnt = 0;set<string>s;while(cin>>t && t[0] != '*'){if(s.count(t)) continue;s.insert(t);int p = t.find('@',0);tf[cnt] = t.substr(0,p);tm[cnt] = t.substr(p+1,t.length()-p+1);cnt++;}readmes();for(int i = 0;i < cnt;i++){if(!tm[i][0]) continue;cout<<"Connection between "<<um<<" and "<<tm[i]<<endl;int mark = 0;cout<<" HELO "<<um<<endl;cout<<" 250\n";cout<<" MAIL FROM:<"<<uf<<'@'<<um<<'>'<<endl;cout<<" 250\n";for(int j = i;j < cnt;j++){if(tm[j] != tm[i]) continue;cout<<" RCPT TO:<"<<tf[j]<<'@'<<tm[j]<<'>'<<endl;if(mta.count(tf[j]) && mta[tf[j]] == tm[j]){mark = 1;cout<<" 250\n";}else cout<<" 550\n";if(j != i) tm[j][0] = 0;}if(mark){cout<<" DATA\n 354\n";cout<<" "<<mes<<".\n 250\n";}cout<<" QUIT\n 221\n";}}return 0;
}
version 2(0ms,参考书上的代码):
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
void parse_addr(const string& s,string& mta,string& user){int p = s.find('@',0);user = s.substr(0,p);mta = s.substr(p + 1);
}
int main(){int n;string mta,user,mta2,user2,t;set<string>addr;while(cin>>t && t[0] != '*'){cin>>mta>>n;while(n--){cin>>user;addr.insert(user + '@' + mta);}}while(cin>>t && t[0] != '*'){parse_addr(t,mta,user);vector<string>mtas;map<string,vector<string> >users;set<string>sented;while(cin>>t && t[0] != '*'){if(sented.count(t)) continue; //消除重复的收件人sented.insert(t);parse_addr(t,mta2,user2);if(!users.count(mta2)){mtas.push_back(mta2);users[mta2] = vector<string>();}users[mta2].push_back(t);}string mes;getline(cin,t); //吃掉‘*’行的回车//在每行的开头都加五个空格,比我之前的做法简便while(getline(cin,t) && t[0] != '*') mes += " " + t +'\n';for(int i = 0;i < mtas.size();i++){cout<<"Connection between "<<mta<<" and "<<mtas[i]<<endl;cout<<" HELO "<<mta<<endl;cout<<" 250\n";cout<<" MAIL FROM:<"<<user<<'@'<<mta<<">\n";cout<<" 250\n";int mark = 0;vector<string>tu = users[mtas[i]];for(int j = 0;j < tu.size();j++){cout<<" RCPT TO:<"<<tu[j]<<">\n";if(addr.count(tu[j])) { mark = 1;cout<<" 250\n";}else cout<<" 550\n";}if(mark){cout<<" DATA\n 354\n";cout<<mes<<" .\n 250\n";}cout<<" QUIT\n 221\n";}}return 0;
}
转载于:https://www.cnblogs.com/JingwangLi/p/10202735.html
814:The Letter Carrier's Rounds相关推荐
- UVa 814 - The Letter Carrier's Rounds
题意 模拟mta发送邮件 模拟的我头皮发麻 记录 有个挺骚的操作记下来了, 有点意思 string text; while(getline(cin, s) && s[0] != '*' ...
- 算法竞赛入门经典(第2版)—第五章(C++与STL入门)
文章目录 零碎知识点整理 题目 10474 - Where is the Marble? 101 - The Blocks Problem 10815 - Andy's First Dictionar ...
- 紫书《算法竞赛入门经典》
紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...
- 《算法竞赛入门经典(第2版)》——学习记录
前言: 这里主要记录本人在学习紫书过程中充分理解过的题目的AC代码,便于以后回顾时查找代码和思路,毕竟看别人的真的有点难懂.此外,本书甚至是本书之外的相关知识学习也可能在此留下记录. 作为一只 ...
- POJ前面的题目算法思路【转】
1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...
- POJ 超详细分类
POJ 各题算法 1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 ...
- RabbitMQ与PHP应用
RabbitMQ与PHP应用 简介 MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连 ...
- java求公式例题_JAVA经典算法40题
1: JAVA经典算法40题 2: [程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 3 ...
- java java算法题目_java常见算法题目
1: JAVA经典算法40题 2: [程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 3 ...
最新文章
- java使用ssh连接Linux并执行命令
- Java函数式折叠,循环,记忆化效率初识
- mapxtreme开发资料全集
- python selenium unittest_python+selenium+unittest单元测试框架
- 怎么设置qq信息同步服务器,QQ输入法如何设置网络同步
- 《计算机组成原理》----2.3 二进制运算
- 粒子群算法组卷_粒子群(PSO)算法概念及代码实现
- python编程口诀_科学网—Python编程技巧汇总 - 高关胤的博文
- LPWSTR 类型的实参与const.char *类型形参不兼容
- 高级应用-路由协议配置
- php堆栈溢出,php - 警告:php_eval() - 堆栈内存溢出
- 流量造假:“蔡徐坤微博转发过亿”幕后推手星援 App 开发者一审获刑五年
- Java短信平台实战第一天
- AI发票扫描识别sdk软件接口
- 用C#通过sql语句操作Sqlserver数据库教程
- 无聊之时用css3自制了好看的button样式和input样式
- 【Uniapp框架】快速开发自己一款APP应用,如何将Uniapp项目快速打包成APP应用
- html如何制作艺术字体,设计华丽金沙艺术字体图片的PS教程
- 计算机处理器哪个最好,电脑处理器,哪个比较好
- css 字体颜色 样式大全
热门文章
- KDD_cup99 pytorch
- 计算机领域认知个人陈述,计算机专业个人陈述十九
- python数据导出excel_python 数据生成excel导出(xlwt,wlsxwrite)代码实例
- rust设置里面那个是能见度_IDEA maven设置里面的Repositories这个设置问题
- docker image aarch64 x86_64_「docker」交叉编译适用于ARM平台的Docker源码
- C++:类-多态的学习和使用
- DeepLearning:环境配置(cuda+cudnn)
- 【视频课】完备理论+4大案例实践,一课深入掌握图像分类各个方向,配套导师永久答疑群...
- 【AI不惑境】AutoML在深度学习模型设计和优化中有哪些用处?
- 【NLP】如何利用BERT来做基于阅读理解的信息抽取