The letter Carrier ' s Rounds (pick)

Source: Internet
Author: User

Description

For a electronic mail application you is to describe the smtp-based communication this 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 was initialized, the sending MTA transmits command lines, one at a time, to the receiving MTA, W Hich returns a three-digit coded response after all command is processed. The sender commands is 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 the users at different MTAs requires separate SMTP sessions.
HELOmyname Identifies the sender to the receiver (yes, there was 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 is sent by the receiving MTA:
221 Closing connection (after QUIT) 250 Action is 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 their name (1 to alphanumeric characters). Following the MTA name is the number of users in this receive mail at this MTA and a list of the users (1 to alphanumeric Characters each). The MTA description is terminated by a asterisk in column 1. Each message begins with the sending user's name and is followed by a list of recipient identifiers. Each identifier have the form [email protected] The message (each line containing no more than characters) begins and Te Rminates with a 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 be exist at the destination MTA. The receiving MTA rejects mail for those users by responding to the RCPT-command with the 550 code. A rejection won't affect delivery to authorized users at the same MTA. If There is not at least one authorized recipient at a particular MTA, the DATA was not sent. Only one SMTP session is used to send a message to the users at a particular MTA. For example, a message to 5 users at the same MTA would have only one SMTP session. Also a message is addressed to the same user only once. The order in which receiving MTAs was contacted by the sender is unspecified. As shown in the sample output, prefix the communication with the communicating MTA names, and indent each communication l Ine.

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*[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

Is the data is too complex, the application of the container in the STL is unfamiliar, there is no difficulty in thinking

Highlights of the following programs:

Store two or three rows of messages with a string string data

#include <iostream>#include<map>#include<string>#include<vector>#include<Set>using namespacestd;voidParse_address (Const string&s,string& User,string&MTA) {    intK=s.find ('@'); User=S.SUBSTR (0, k);//break [email protected]Mta=s.substr (k +1);}intMain () {intN; stringS,t,user1,mta1,user2,mta2; Set<string>address;  while(cin>>s&&s!="*"){//user information under the MTACin>>s>>N;  while(n--) {cin>>T; Address.insert (t+'@'+s); }    }     while(cin>>s&&s!="*") {parse_address (S,USER1,MTA1); //SenderVector<string>mta;//all MTA that need to be connected, in order of inputmap<string,vector<string>>dest;//users that each MTA needs to send        Set<string>Vis;  while(cin>>t&&t!="*"){//Recipientparse_address (T,USER2,MTA2); if(Vis.count (t))Continue;//the recipient repeats without insertingVis.insert (t); if(!dest.count (MTA2)) {//the MTA vector does not have the MTA inserted and corresponds to the string MTA in the mapMta.push_back (MTA2); DEST[MTA2]=vector<string>();        } dest[mta2].push_back (t); //Insert [email protected] complete form} getline (cin,t); //Eat "*"        stringdata;  while(Getline (cin,t) &&t[0]!='*') data+="  "+t+"\ n";//Save the entire message in a string of data//cout<< "* * *" <<data<< "* * *" <<endl;         for(intI=0; I<mta.size (); i++){            stringMta2=Mta[i]; Vector<string>users=dest[mta2];//users are the user who needs to send the Dest[mata2],mata2cout<<"Connection between"<<mta1<<" and"<<mta2<<Endl; cout<<"HELO"<<mta1<<"\ n"; cout<<"250\n"; cout<<"MALL from:<"<<s<<">\n"; cout<<"250\n"; BOOLok=false;  for(intI=0; I<users.size (); i++) {cout<<"RCPT to:<"<<users[i]<<">\n"; if(Address.count (Users[i])) {OK=true; cout<<"250\n"; }                Elsecout<<"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 (pick)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.