#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<stack>
#include<iomanip>
using namespace std;
int main()
{
map<string,set<string> > str2set;
map<string,int> str2int;
string s;
getline(cin,s);
int amount=0;
while(s[0]!='*')
{
int t=s.find(' ',4);
string name=s.substr(4,t-4);
str2int[name]=amount;
t++;
int t2=s.find(' ',t);
while(t2!=-1)
{
string temp=s.substr(t,t2-t);
if(str2set.count(name)==0)
{
set<string> a;
str2set[name]=a;
}
str2set[name].insert(temp);
t=t2+1;
t2=s.find(' ',t);
}
string temp=s.substr(t);
str2set[name].insert(temp);
s="";
getline(cin,s);
amount++;
}
string st;
cin>>st;
int i;
while(1)
{
queue<pair<string,string> > *q=new queue<pair<string,string> >[amount];
if(st[0]=='*')
break;
string sender;
sender=st;
vector<string> rcpt;
cin>>st;
while(st[0]!='*')
{
rcpt.push_back(st);
cin>>st;
}
vector<string> content;
string t11;
getline(cin,t11);//消除多余的换行
st="";
getline(cin,st);
while(st[0]!='*')
{
content.push_back(st);
st="";
getline(cin,st);
}
queue<int> q2;
set<int> Set;
set<pair<string,string> > Set2;
for(i=0;i<rcpt.size();i++)
{
pair<string,string> temp;
int t=rcpt[i].find('@',0);
temp.first=rcpt[i].substr(0,t);
temp.second=rcpt[i].substr(t+1);
int t2=str2int[temp.second];
if(Set.count(t2)==0)
{
Set.insert(t2);
q2.push(t2);
}
if(Set2.count(temp)==0)
{
q[t2].push(temp);
Set2.insert(temp);
}
}
int index1=sender.find('@',0);
string start=sender.substr(index1+1);
while(!q2.empty())
{
pair<string,string> temp1;
int index=q2.front();
q2.pop();
if(!q[index].empty())
{
cout<<"Connection between "<<start<<" and "<<q[index].front().second<<endl;
cout<<" "<<"HELO "<<start<<endl;
cout<<" "<<"250"<<endl;
cout<<" "<<"MAIL FROM:<"<<sender<<">"<<endl;
cout<<" "<<"250"<<endl;
}
int flag=0;
while(!q[index].empty())
{
temp1=q[index].front();
q[index].pop();
cout<<" "<<"RCPT TO:<"<<temp1.first<<"@"<<temp1.second<<">"<<endl;
if(str2set[temp1.second].count(temp1.first))
{
cout<<" "<<"250"<<endl;
flag=1;
}
else
{
cout<<" "<<"550"<<endl;
}
}
if(flag)
{
cout<<" "<<"DATA"<<endl<<" "<<"354"<<endl;
for(i=0;i<content.size();i++)
cout<<" "<<content[i]<<endl;
cout<<" "<<"."<<endl<<" "<<"250"<<endl;
}
cout<<" "<<"QUIT"<<endl<<" "<<"221"<<endl;
}
cin>>st;
}
return 0;
}
UVa 814 The Lettter Carrier's Rounds
最新推荐文章于 2022-04-05 19:13:05 发布