Description

For an electronic mail application you are to describe the SMTP-based communication that takes place between pairs of MTAs. The sender's User Agent gives a formatted message to the sending Message Transfer Agent (MTA). The sending MTA communicates with the receiving MTA using the Simple Mail Transfer Protocol (SMTP). The receiving MTA delivers mail to the receiver's User Agent. After a communication link is initialized, the sending MTA transmits command lines, one at a time, to the receiving MTA, which returns a three-digit coded response after each command is processed. The sender commands are shown below in the order sent for each message. There is more than one RCPT TO line when the same message is sent to several users at the same MTA. A message to users at different MTAs requires separate SMTP sessions.

HELO myname Identifies 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

The input contains descriptions of MTAs followed by an arbitrary number of messages. Each MTA description begins with the MTA designation and its name (1 to 15 alphanumeric characters). Following the MTA name is the number of users that receive mail at that MTA and a list of the users (1 to 15 alphanumeric characters each). The MTA description is terminated by an asterisk in column 1. Each message begins with the sending user's name and is followed by a list of recipient identifiers. Each identifier has the form user@mtaname. The message (each line containing no more than 72 characters) begins and terminates with an asterisk in column 1. A line with an asterisk in column 1 instead of a sender and recipient list indicates the end of the entire input.

Output

For each message, show the communication between the sending and receiving MTAs. Every MTA mentioned in a message is a valid MTA; however, message recipients may not exist at the destination MTA. The receiving MTA rejects mail for those users by responding to the RCPT TO command with the 550 code. A rejection will not affect delivery to authorized users at the same MTA. If there is not at least one authorized recipient at a particular MTA, the DATA is not sent. Only one SMTP session is used to send a message to users at a particular MTA. For example, a message to 5 users at the same MTA will have only one SMTP session. Also a message is addressed to the same user only once. The order in which receiving MTAs are contacted by the sender is unspecified. As shown in the sample output , prefix the communication with the communicating MTA names, and indent each communication line.

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(摘)的更多相关文章

  1. UVA 814 The Letter Carrier's Rounds

    大致翻译: 对于电子邮件应用程序,您需要描述发生在成对mta之间的基于smtp的通信.发送方 的用户代理向发送消息传输代理(MTA)提供格式化的消息.发送MTA使用SimpleMail 传输协议(SM ...

  2. UVA 814 The Letter Carrier's Rounds(JAVA基础map)

    题解:就是按照题目模拟就好 但是这个题目让我发现了我Java里面许多问题 具体看代码,但是还是分为这几个方面 属性的作用域问题,缓冲区问题,map与list映射的问题,输出多个空格不一定是/t,反转思 ...

  3. 紫书第5章 C++STL

    例题 例题5-1 大理石在哪儿(Where is the Marble?,Uva 10474) 主要是熟悉一下sort和lower_bound的用法 关于lower_bound: http://blo ...

  4. [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  5. 17. Letter Combinations of a Phone Number

    题目: Given a digit string, return all possible letter combinations that the number could represent. A ...

  6. 什么是Unicode letter

    起因:从一段代码说起 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  7. LeetCode——Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  8. 【摘选引用】在安全的SQL 密码也不过如此

    SQL密码再安全也禁不住破解!!! http://www.sqlservercentral.com/articles/password+cracking/96540/ 备注:[摘选引用]是本人日常收集 ...

  9. OpenJudge2728:摘花生 解题报告

    2728:摘花生 总时间限制:  1000ms 内存限制: 65536kB 描述 Hello Kitty 想摘点花生送给她喜欢的米老鼠.她来到一片有网格状道路的矩形花生地(如下图),从西北角进去,东南 ...

随机推荐

  1. hdu5672 尺取法

    StringTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Subm ...

  2. 把python项目部署到centos里

    .安装centos VMware9下面安装centos .在centos下面设置共享文件夹为你本地的论坛的代码,然后设置网络为桥接:直接连接到物理网络,赋值网络连接状态 .进入forum_svr.py ...

  3. JavaScript语法学习笔记

    1.关于执行JavaScript代码的方法: 第一种方法是将JavaScript代码放到文档<head>标签中的<script>标签之间: <head>     & ...

  4. phantomjs 渲染

    phantomjs 可以将web页面渲染并保存为扩展名为PNG,GIF,JPEG,PDF的指定文件 render viewportSize可以改变可视窗体大小 zoomFactor调整缩放比例 cli ...

  5. Android studio快捷键Mac版本

    为了方便大家记住这些小技巧和快捷键,我把它写成了一个插件,欢迎大家下载使用:http://chunsheng.me/EasyShortcut/ 快捷键 描述 通用------------------- ...

  6. CSS3笔记(一)

    最开始的时候 CSS3产生的一个新属性是一个浏览器的私有的,然后W3C 可能会拿来采用做个标准,再没公布标准之前就只能用私有属性(加前缀)来表达各自厂商的实现,主要是CSS3刚出现那会儿,它暗示该CS ...

  7. 【好程序员笔记分享】——iOS开发之纯代码键盘退出

    -iOS培训,iOS学习-------型技术博客.期待与您交流!------------ iOS开发之纯代码键盘退出(非常简单)     iOS开发之纯代码键盘退出 前面说到了好几次关于键盘退出的,但 ...

  8. debian系统下安装ssh服务

    它是什么?? SSH 为 Secure Shell 的缩写,简单地说,SSH 为建立在应用层基础上的安全协议.SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议.利用 SSH 协议可 ...

  9. iOS: 消息通信中的Notification&KVO

    iOS: 消息通信中的Notification&KVO 在 iOS: MVC 中,我贴了张经典图: 其中的Model向Controller通信的Noification&KVO为何物呢? ...

  10. windows下将隐藏文件通过命令行改变为普通的显示文件

    attrib -h -s *.* /s /d 不懂的看下 attrib /? 帮助.保存为bat也可以.