UVa 814 - The Letter Carrier's Rounds(模拟)

模拟邮件的发送,把每一个地址保存下来, 然后在搜索能否找到匹配的地址。

#include <iostream>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <vector>

using namespace std;

void parse_address(string const s, string& user, string& mta) {
    int t = s.find('@');
    user = s.substr(0, t);
    mta = s.substr(t + 1);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("test", "r", stdin);
#endif // ONLINE_JUDGE
    int k;
    string s, t, user1, user2, mta1, mta2;
    set<string> addr;

    while(cin >> s&& s[0] != '*') {
        cin >> t >> k;
        while(k--) {cin >> s; addr.insert(s + '@' + t);}
    }

    while(cin >> s&& s[0] != '*') {
        parse_address(s, user1, mta1);

        vector<string> mta;
        map<string, vector<string> > dest;
        set<string> vis;

        while(cin >> t&& t[0] != '*') {
            if(vis.count(t)) continue;
            vis.insert(t);
            parse_address(t, user2, mta2);
            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[0] != '*') data += "     " + t + "\n";

        for(int i = 0; i < mta.size(); i++) {
            mta2 = mta[i];
            vector<string> users = dest[mta2];
            cout << "Connection between " << mta1 << " and " << mta2 << "\n";
            cout << "     HELO "<< mta1 << "\n";
            cout << "     250\n";
            cout << "     MAIL FROM:<" << user1 << "@" << mta1 << ">\n";
            cout << "     250\n";
            bool ok = false;
            for(int i = 0; i < users.size(); i++) {
                cout << "     RCPT TO:<" << users[i] << ">\n";
                if(addr.count(users[i])) {ok = true; cout << "     250\n"; }
                else cout << "     550\n";
            }
            if(ok) {
                cout << "     DATA\n     354\n";
                cout << data;
                cout << "     .\n" << "     250\n";
            }
            cout << "     QUIT\n     221\n";
        }
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值