uva 814 The Letter Carrier's Rounds

来源:互联网 发布:淘宝卖的哈曼卡顿真假 编辑:程序博客网 时间:2024/05/18 02:35

题目:The Letter Carrier's Rounds


题意:输入MTA以及在同一个MTA中的所有人。再输入发件人和收件人以及信息的内容,要求整理成题目所示的格式输出。


思路:模拟题,将数据读入后按顺序输出。


注意:(1)注意按顺序输出,所以不能用map只能用vector存储。

(2)注意重复的情况要。


代码:

#include<cstdio>#include<iostream>#include<string>#include<vector>#include<set>#include<map>using namespace std;struct USER {string Before;string Name;string Adress;USER() {}USER(string x) {Before=x;}void spl() {int pos=Before.find('@');Name=Before.substr(0,pos);Adress=Before.substr(pos+1,Before.size()-pos);}};map<string,vector<string> > user;USER sender;vector<USER> rec;vector<string> Data;vector<string> mp;void init() {rec.clear();Data.clear();mp.clear();}int main() {string x;while(cin>>x&&x[0]!='*') {cin>>x;int num;cin>>num;for(int i=0; i<num; i++) {string y;cin>>y;user[x].push_back(y);}}while(cin>>sender.Before&&sender.Before[0]!='*') {init();sender.spl();while(cin>>x&&x[0]!='*') {bool flag=true;for(int i=0;i<rec.size();i++){if(rec[i].Before==x){flag=false;break;}}if(flag==false) continue;rec.push_back(USER(x));rec[rec.size()-1].spl();flag=true;for(int i=0;i<mp.size();i++){if(mp[i]==rec[rec.size()-1].Adress){flag=false;break;}}if(flag==true)mp.push_back(rec[rec.size()-1].Adress);}string d;getchar();while(getline(cin,d)&&d[0]!='*') {Data.push_back(d);}for(int it=0; it<mp.size(); it++) {cout<<"Connection between "<<sender.Adress<<" and "<<mp[it]<<endl;cout<<"     HELO "<<sender.Adress<<endl;cout<<"     250\n";cout<<"     MAIL FROM:<"<<sender.Before<<">\n";cout<<"     250\n";bool F=false;for(int i=0; i<rec.size(); i++) {if(rec[i].Adress==mp[it]) {cout<<"     RCPT TO:<"<<rec[i].Before<<">\n";bool flag=false;for(int j=0; j<user[mp[it]].size(); j++) {if(user[mp[it]][j]==(rec[i].Name)) {F=true;flag=true;break;}}if(flag==false) cout<<"     550\n";else cout<<"     250\n";}}if(F==true) {cout<<"     DATA\n     354\n";for(int i=0; i<Data.size(); i++) {cout<<"     ";cout<<Data[i]<<endl;}cout<<"     .\n     250\n";}cout<<"     QUIT\n     221\n";}}return 0;}

阅读全文
2 0