POJ 1876 The Letter Carrier‘s Rounds G++ 模拟 文本输入

这篇博客详细介绍了如何解决编程竞赛POJ 1876问题,使用G++语言进行模拟实现。内容涵盖了问题的背景,算法设计,代码实现以及可能的优化策略。
摘要由CSDN通过智能技术生成

#include <iostream>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <vector>
using namespace std;
//英语      看博友分析     抄博友程序      模拟     文件输入 
void fen(string s,string &mta,string &user)
{
	int p=s.find('@');
	user=s.substr(0,p);
	mta=s.substr(p+1);
}
int main()
{
	//freopen("1876.txt","r",stdin); 
	string t;
	set<string> addr;
	while(cin>>t && t!="*")
	{
		string mta;
		int n;
		cin>>mta>>n;
		while(n--)
		{
			string user;
			cin>>user;
			addr.insert(user+"@"+mta);//所有存在的用户和地址 
		}
	} 
	while(cin>>t && t!="*")
	{
		string mta,user;//发件地址 发件人
		fen(t,mta,user);
		//cout<<t<<" "<<mta<<" "<<user<<endl; 
		set<string> shou;//收件地址和收件人 
		vector<string> sd;//收件地址
		map<string,vector<string> > mp;//相同收件地址的不同收件人及其收件地址 
		while(cin>>t && t!="*")
		{
			if(shou.count(t))
			{
				continue;
			}
			shou.insert(t); 
			string mta2,user2;//收件地址和收件人 
			fen(t,mta2,user2);
			if(mp.count(mta2)==0)
			{
				sd.push_back(mta2);
				mp[mta2]=vector<string>();
			}
			mp[mta2].push_back(t);
		}
		getline(cin,t);
		string mes;//文本 
		while(getline(cin,t) && t!="*")
		{
			mes+="     "+t+"\n";//抄博友程序 
		}
		for(int i=0;i<sd.size();i++)//遍历收件人地址 
		{
			cout<<"Connection between "<<mta<<" and "<<sd[i]<<endl;//抄博友程序 
            cout<<"     HELO "<<mta<<endl;
            cout<<"     250\n";
            cout<<"     MAIL FROM:<"<<user<<'@'<<mta<<">\n";
            cout<<"     250\n";	
			int mark=0;
			vector<string> tv=mp[sd[i]];//方便程序书写 
			for(int j=0;j<tv.size();j++)
			{
                 cout<<"     RCPT TO:<"<<tv[j]<<">\n";//抄博友程序 
                 if(addr.count(tv[j])) { mark = 1;cout<<"     250\n";}//收件信息准确 
                 else cout<<"     550\n";				
			}
			if(mark)
			{
                cout<<"     DATA\n     354\n";//抄博友程序 
                cout<<mes<<"     .\n     250\n";				
			} 
            cout<<"     QUIT\n     221\n";
		}
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值