UVa 814 The Lettter Carrier's Rounds

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值