您的位置:首页 > 其它

UVA 814 MTA 模拟

2017-04-18 17:30 169 查看
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
//#define LOCAL
#include<cstdio>
using namespace std;

void getInformation(string& ss, string user, string & mat)
{
int k = ss.find('@');
user = ss.substr(0, k);
mat = ss.substr(k+1);
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif // LOCAL
int n;
string s, t, s1, s2, mta1, mta2, user1, user2;

// 对MAT进行整理 , 变成 姓名@地址的形式.
set<string> adds;
while(cin >> s1 && s1 != "*"){
cin >> s >> n;
while(n--){
cin >> s2;
adds.insert(s2 + "@" + s);
}
}

// 处理发件人的信息, 把姓名和地址分开
while(cin >> s && s != "*")
{
getInformation(s, user1, mta1);  //  关于字符串的处理
vector<string> mta;
map<string, vector<string> > dest;
set<string> vis;
while(cin >> t && t != "*")
{
getInformation(t, user2, mta2);
if(vis.count(t)) continue;  // 重复的收件人, 直接跳过后续工作
vis.insert(t);
if(!dest.count(mta2)) {
mta.push_back(mta2);  dest[mta2] = vector<string>();}
dest[mta2].push_back(t);
}
getline(cin, t);
// 正文的处理,整合成一句话
string data;
while(getline(cin, t) && t != "*") data += "     " + t + "\n";   // 对信息内容的处理

for(int i = 0; i < mta.size(); i++)
{
string mta2 = mta[i];
vector<string> users = dest[mta2];
cout << "Connection between " << mta1 << " and " << mta2 << endl;
cout << "     HELO " << mta1 <<endl << "     250" <<endl;
cout << "     MAIL FROM:<" << s << ">" << endl << "     250" <<endl;
bool ok = false;
for(int i = 0; i < users.size(); i++){
cout << "     RCPT TO:<" << users[i] << ">" <<endl ;
if(adds.count(users[i])) {ok = true; cout << "     250\n";}
else cout << "     550\n";
}
if(ok)
{
cout << "     DATA\n"; cout << "     354\n";
cout << data;
cout << "     .\n" <<"     250\n";
}
cout << "     QUIT\n" << "     221\n";
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva