UVa 814 - The Letter Carrier's Rounds

题意

模拟mta发送邮件
模拟的我头皮发麻

记录

有个挺骚的操作记下来了, 有点意思

string text;
while(getline(cin, s) && s[0] != '*')
            text += "     " + s + "\n";

AC代码

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

using namespace std;

set<string> email, wait;
vector<string> vec;
map<string,vector<string> > countnum;

void findmta( string &name, string &mta, string s ){
    int mrk = s.find('@');
    name = s.substr(0,mrk);
    mta = s.substr(mrk+1);
    //cout << name << endl << mta << endl;
}

int main()
{
    string s, s1, s2, ss, name1, mta1, name2, mta2;
    vector<string>::iterator it;
    int n;
    size_t i, j;
    while( cin >> s )
    {
        if( s == "*" )  break;
        if( s == "MTA" ){
            cin >> s1;
            cin >> n;
            while(n--){
                s2 = "";
                cin >> s2;
                email.insert(s2+"@"+s1);
            }
        }
    }
    while( cin >> s && s != "*" )
    {
        findmta(name1,mta1,s);
        while( cin >> ss && ss != "*" )
        {
            findmta(name2, mta2, ss);
            if(wait.count(ss)) continue;
            wait.insert(ss);
            if( !countnum.count(mta2) ){
                vec.push_back(mta2);
                countnum[mta2] = vector<string>();
            }
            countnum[mta2].push_back(ss);
            //countnum[mta2]++;
        }
        getchar();
        string text;
        while(getline(cin, s) && s[0] != '*')
            text += "     " + s + "\n";
        for( i = 0; i < vec.size(); i++ ){
            vector<string> adds = countnum[vec[i]];
            cout << "Connection between " << mta1 << " and " << vec[i] << endl;
            cout << "     HELO " << mta1 << endl << "     250" << endl;
            cout << "     MAIL FROM:<" << name1 << "@" << mta1 << ">" << endl << "     250" << endl;
            bool flag = false;
            for( j = 0; j < adds.size(); j++){
                cout << "     RCPT TO:<" << adds[j] << ">" << endl;
                if( email.count(adds[j]) ){
                    flag = true;
                    cout << "     250" << endl;
                }
                else    cout << "     550" << endl;
            }
                if( flag )
                    cout << "     DATA" << endl << "     354" << endl << text << "     ." << endl << "     250" << endl;
                cout << "     QUIT" << endl << "     221" << endl;
        }
        if( !wait.empty() ) wait.clear();
        if( !countnum.empty() ) countnum.clear();
        if( !vec.empty() )  vec.clear();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值