UVA 814 MTA 模拟

来源:互联网 发布:霍建华与林心如 知乎 编辑:程序博客网 时间:2024/05/16 15:06
#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;}
0 0
原创粉丝点击