The Letter Carrier's Rounds(摘)
Description
HELO
mynameIdentifies the sender to the receiver (yes, there is only one L). MAIL FROM:
<sender>Identifies the message sender RCPT TO:
<user>Identifies one recipient of the message DATA
Followed by an arbitrary number of lines of text comprising the message body, ending with a line containing a period in column one. QUIT
Terminates the communication.
The following response codes are sent by the receiving MTA:
221 Closing connection (after QUIT) 250 Action was okay (after MAIL FROM and RCPT TO specifying an acceptable user, or completion of a message) 354 Start sending mail (after DATA) 550 Action not taken; no such user here (after RCPT TO with unknown user)
Input
Output
Sample Input
MTA London 4 Fiona Paul Heather Nevil
MTA SanFrancisco 3 Mario Luigi Shariff
MTA Paris 3 Jacque Suzanne Maurice
MTA HongKong 3 Chen Jeng Hee
MTA MexicoCity 4 Conrado Estella Eva Raul
MTA Cairo 3 Hamdy Tarik Misa
*
Hamdy@Cairo Conrado@MexicoCity Shariff@SanFrancisco Lisa@MexicoCity
*
Congratulations on your efforts !!
--Hamdy
*
Fiona@London Chen@HongKong Natasha@Paris
*
Thanks for the report! --Fiona
*
*
Sample Output
Connection between Cairo and MexicoCity
HELO Cairo
250
MAIL FROM:<Hamdy@Cairo>
250
RCPT TO:<Conrado@MexicoCity>
250
RCPT TO:<Lisa@MexicoCity>
550
DATA
354
Congratulations on your efforts !!
--Hamdy
.
250
QUIT
221
Connection between Cairo and SanFrancisco
HELO Cairo
250
MAIL FROM:<Hamdy@Cairo>
250
RCPT TO:<Shariff@SanFrancisco>
250
DATA
354
Congratulations on your efforts !!
--Hamdy
.
250
QUIT
221
Connection between London and HongKong
HELO London
250
MAIL FROM:<Fiona@London>
250
RCPT TO:<Chen@HongKong>
250
DATA
354
Thanks for the report! --Fiona
.
250
QUIT
221
Connection between London and Paris
HELO London
250
MAIL FROM:<Fiona@London>
250
RCPT TO:<Natasha@Paris>
550
QUIT
221
就是数据太复杂,对于stl中容器的应用很生疏,没啥思维难点
以下程序的亮点:
用一个string字符串data存储两三行的邮件
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<set>
using namespace std; void parse_address(const string&s,string& user,string&mta)
{
int k=s.find('@');
user=s.substr(,k); //将user1@mta1 分解开来
mta=s.substr(k+);
}
int main()
{
int n;
string s,t,user1,mta1,user2,mta2;
set<string>address; while(cin>>s&&s!="*"){ //mta下的用户信息
cin>>s>>n;
while(n--){
cin>>t;
address.insert(t+'@'+s);
}
}
while(cin>>s&&s!="*"){
parse_address(s,user1,mta1); //发件人 vector<string>mta; //所有需要连接的mta,按照输入顺序
map<string,vector<string>>dest; //每个mta需要发送的用户
set<string>vis; while(cin>>t&&t!="*"){ //收件人
parse_address(t,user2,mta2);
if(vis.count(t))continue; //收件人重复则不插入
vis.insert(t);
if(!dest.count(mta2)){ //mta向量中没有该mta就插入并将向量与map中的string mta对应起来
mta.push_back(mta2);
dest[mta2]=vector<string>();
}
dest[mta2].push_back(t); //插入user@mta 完整形式
}
getline(cin,t); //吃掉"*" string data;
while(getline(cin,t)&&t[]!='*')data+=" "+t+"\n"; //将整个邮件存入一个字符串data中 //cout<<"***"<<data<<"***"<<endl;
for(int i=;i<mta.size();i++){
string mta2=mta[i];
vector<string>users=dest[mta2]; //users即为dest[mata2],mata2对应的需要发送的用户
cout<<"Connection between "<<mta1<<" and "<<mta2<<endl;
cout<<" HELO "<<mta1<<"\n";
cout<<" 250\n";
cout<<" MALL FROM:<" <<s<<">\n";
cout<<" 250\n";
bool ok=false;
for(int i=;i<users.size();i++){
cout<<"RCPT TO:<"<<users[i]<<">\n";
if(address.count(users[i])){
ok=true;
cout<<" 250\n";
}
else cout<<" 500\n";
}
if(ok){
cout<<" DATA\n";
cout<<" 254\n";
cout<<data;
cout<<".\n";
cout<<" 250\n";
}
cout<<" QUIT\n";
cout<<" 221\n";
}
}
//system("pause");
return ;
}
The Letter Carrier's Rounds(摘)的更多相关文章
- UVA 814 The Letter Carrier's Rounds
大致翻译: 对于电子邮件应用程序,您需要描述发生在成对mta之间的基于smtp的通信.发送方 的用户代理向发送消息传输代理(MTA)提供格式化的消息.发送MTA使用SimpleMail 传输协议(SM ...
- UVA 814 The Letter Carrier's Rounds(JAVA基础map)
题解:就是按照题目模拟就好 但是这个题目让我发现了我Java里面许多问题 具体看代码,但是还是分为这几个方面 属性的作用域问题,缓冲区问题,map与list映射的问题,输出多个空格不一定是/t,反转思 ...
- 紫书第5章 C++STL
例题 例题5-1 大理石在哪儿(Where is the Marble?,Uva 10474) 主要是熟悉一下sort和lower_bound的用法 关于lower_bound: http://blo ...
- [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 17. Letter Combinations of a Phone Number
题目: Given a digit string, return all possible letter combinations that the number could represent. A ...
- 什么是Unicode letter
起因:从一段代码说起 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...
- LeetCode——Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【摘选引用】在安全的SQL 密码也不过如此
SQL密码再安全也禁不住破解!!! http://www.sqlservercentral.com/articles/password+cracking/96540/ 备注:[摘选引用]是本人日常收集 ...
- OpenJudge2728:摘花生 解题报告
2728:摘花生 总时间限制: 1000ms 内存限制: 65536kB 描述 Hello Kitty 想摘点花生送给她喜欢的米老鼠.她来到一片有网格状道路的矩形花生地(如下图),从西北角进去,东南 ...
随机推荐
- c#鼠标在控件上面,然后显示文字
先添加toolTip控件到界面 然后每个控件的属性会多一项 ToolTip 第一种:直接给里面加文字 第二种: private void pictureBox_topmost_MouseHover(o ...
- Mac系统cocos2dx + android 开发环境配置
Mac系统cocos2dx + android 开发环境配置 /****************************************************** 这遍文章主要转载自:htt ...
- hadoop之MapReduce WordCount分析
MapReduce的设计思想 主要的思想是分而治之(divide and conquer),分治算法. 将一个大的问题切分成很多小的问题,然后在集群中的各个节点上执行,这既是Map过程.在Map过程结 ...
- 使用ES6进行开发的思考
ECMAScript6已经于近日进入了RC阶段,而早在其处于社区讨论时,我就开始一直在尝试使用ES6进行开发的方案.在Babel推出后,基于ES6的开发也有了具体可执行的解决方案,无论是Build还是 ...
- JSP EL
一.JSP EL语言定义 E L(Expression Language) 目的:为了使JSP写起来更加简单. 表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 ...
- 添加AdMob 错误记录
依照官方教程添加文件及其 frameWork后 发现运行报错 错误如下 Undefined symbols for architecture i386: "_OBJC_CLASS_$_ASI ...
- awk的接口实现方案1
module/a.awk function sum(a, b) { return a + b } module/b.awk function sum(a, b) { return a * b } ma ...
- Netbeans7.4+Weblogic11g+Spring3.2.4操作JdbcTemplate
第一步:在Weblgic11g管理界面:http://localhost:7001/console 中建立数据源,我建立的jndi名称为:sjsstjndi 第二步:需要导入spring的以下包:使用 ...
- InnoSetup中枚举出INI文件的所有sections和键值
原文 http://blog.chinaunix.net/uid-23480430-id-3016899.html InnoSetup支持一些INI文件操作函数, 例如GetIniString,Ini ...
- AQS详解
一.概述 谈到并发,不得不谈ReentrantLock:而谈到ReentrantLock,不得不谈AbstractQueuedSynchronized(AQS)! 类如其名,抽象的队列式的同步器,AQ ...