博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
The Letter Carrier's Rounds(摘)
阅读量:6506 次
发布时间:2019-06-24

本文共 5599 字,大约阅读时间需要 18 分钟。

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 NevilMTA SanFrancisco 3 Mario Luigi Shariff MTA Paris 3 Jacque Suzanne MauriceMTA HongKong 3 Chen Jeng HeeMTA MexicoCity 4 Conrado Estella Eva RaulMTA 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
#include
#include
#include
#include
using namespace std;void parse_address(const string&s,string& user,string&mta){ int k=s.find('@'); user=s.substr(0,k); //将user1@mta1 分解开来 mta=s.substr(k+1);}int main(){ int n; string s,t,user1,mta1,user2,mta2; set
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
mta; //所有需要连接的mta,按照输入顺序 map
>dest; //每个mta需要发送的用户 set
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
(); } dest[mta2].push_back(t); //插入user@mta 完整形式 } getline(cin,t); //吃掉"*" string data; while(getline(cin,t)&&t[0]!='*')data+=" "+t+"\n"; //将整个邮件存入一个字符串data中 //cout<<"***"<
<<"***"<
users=dest[mta2]; //users即为dest[mata2],mata2对应的需要发送的用户 cout<<"Connection between "<
<<" and "<
<
\n"; cout<<" 250\n"; bool ok=false; for(int i=0;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<

 

 

转载地址:http://zgwfo.baihongyu.com/

你可能感兴趣的文章
深入分析面向对象中的封装作用
查看>>
JAVA 位操作学习
查看>>
mybatis实战教程(mybatis in action)之三:实现数据的增删改查
查看>>
【转】mysql的cardinality异常,导致索引不可用
查看>>
Babel6.x 转换ES6
查看>>
深刻理解Python中的元类(metaclass)
查看>>
mysql 5.7 zip 文件在 windows下的安装
查看>>
Java编程的逻辑 (44) - 剖析TreeSet
查看>>
address元素
查看>>
[LeetCode] Word Squares 单词平方
查看>>
d 属性: 赋予字段执行动作的能力
查看>>
家庭局域网接入Internet
查看>>
每天一个linux命令(2):cd命令
查看>>
软件测试--安装软件
查看>>
Android View体系(六)从源码解析Activity的构成
查看>>
MVP模式及性能优化
查看>>
RocketMQ最佳实践
查看>>
Arduino学习笔记二:修改LED点灯程序
查看>>
Intellij Idea 13 快捷键(与Eclipse比对)以及基本的设置
查看>>
Hadoop Hive概念学习系列之hive里的优化和高级功能(十四)
查看>>