The Letter Carrier's Rounds(摘)
Posted Not-Bad
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The Letter Carrier's Rounds(摘)相关的知识,希望对你有一定的参考价值。
Description
The following response codes are sent by the receiving MTA:
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.
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 * [email protected] [email protected] [email protected] [email protected] * Congratulations on your efforts !! --Hamdy * [email protected] [email protected] [email protected] * Thanks for the report! --Fiona * *
Sample Output
Connection between Cairo and MexicoCity
HELO Cairo
250
MAIL FROM:<[email protected]>
250
RCPT TO:<[email protected]>
250
RCPT TO:<[email protected]>
550
DATA
354
Congratulations on your efforts !!
--Hamdy
.
250
QUIT
221
Connection between Cairo and SanFrancisco
HELO Cairo
250
MAIL FROM:<[email protected]>
250
RCPT TO:<[email protected]>
250
DATA
354
Congratulations on your efforts !!
--Hamdy
.
250
QUIT
221
Connection between London and HongKong
HELO London
250
MAIL FROM:<[email protected]>
250
RCPT TO:<[email protected]>
250
DATA
354
Thanks for the report! --Fiona
.
250
QUIT
221
Connection between London and Paris
HELO London
250
MAIL FROM:<[email protected]>
250
RCPT TO:<[email protected]>
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(0,k); //将[email protected] 分解开来 mta=s.substr(k+1); } 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); //插入[email protected] 完整形式 } getline(cin,t); //吃掉"*" string data; while(getline(cin,t)&&t[0]!=‘*‘)data+=" "+t+"\n"; //将整个邮件存入一个字符串data中 //cout<<"***"<<data<<"***"<<endl; for(int i=0;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=0;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 0; }
以上是关于The Letter Carrier's Rounds(摘)的主要内容,如果未能解决你的问题,请参考以下文章
The Letter Carrier's Rounds UVA - 814
UVA 814 The Letter Carrier's Rounds(JAVA基础map)
ZooKeeper Commands: The Four Letter Words 获取监控状态