814-The Letter Carrier's Rounds【模拟、STL、被坑了】

一道比较水的STL的练习题,被坑的老妈都认不出来了

被坑的地方是 在一次输入中 你如果给同一个人多次发邮件,那么只输出一次结果,我了个擦,被坑死了。。还是英语烂,直接跪了

跑的比较慢,没做优化

#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<cstring>
#include<set>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn = 11111;
const int maxd = 5555;
map<string,int>name;        //运营商映射
vector<string>ID[maxn];
int cnt = 1;
void GetMAT(){
    char str[maxd],str2[maxd];
    while(cin >> str){
        if(str[0] == '*') break;
        int m;
        cin >> str >> m;
        name[string(str)] = cnt;
        for(int i = 0; i < m; i++){
            cin >> str2;
            ID[cnt].push_back(str2);
        }
        cnt ++;
    }
    return;
}
bool GetAddress(char str[3][maxd]){
    int L,now = 1,pos = 0;
    cin >> str[0];
    if(str[0][0] == '*') return false;
    L = strlen(str[0]);
    for(int i = 0; i <= L; i ++){
        if(str[0][i] == '@' || str[0][i] == '\0'){
            str[now][pos] = '\0';
            now ++;
            pos = 0;
        }
        else
            str[now][pos++] = str[0][i];
    }
    return true;
}
char str2[maxd][3][maxd];
char data[maxd][maxd];
set<string>have_send;
bool SendEmail(){
    have_send.clear();
    char str[3][maxd];
    int vis[maxd] = {0};
    if(!GetAddress(str)) return false;
    int ret = 0,ret2 = 0;
    string sender(str[1]);
    string   matt(str[2]);
    while(GetAddress(str2[ret])) ret++;
    getchar();
    while(gets(data[ret2])){
        if(data[ret2][0] == '*') break;
        ret2++;
    }
    for(int i = 0; i < ret; i++){
        string user(str2[i][1]);
        string  mat(str2[i][2]);
        int fr = name[mat];     //找出运营商
        if(!vis[fr]){
            vis[fr] = 1;
            cout << "Connection between " << matt << " and " << mat << endl;
            cout << "     HELO " << matt << endl;
            cout << "     250"   << endl;
            cout << "     MAIL FROM:" << "<" << sender << "@" << matt << ">" << endl;
            cout << "     250"   << endl;
            int ok = 0;
            //发消息
            for(int j = i; j < ret; j++){
                string us(str2[j][1]);
                string ma(str2[j][2]);
                int f = name[ma];
                if(f == fr && !have_send.count(string(us + "@" + ma))){
                    have_send.insert(string(us + "@" + ma));
                    cout << "     RCPT TO:<" << us << "@" << ma << ">" << endl;
                    int have_find = 0;
                    for(int k = 0; k < ID[f].size(); k++){
                        if(ID[f][k] == us){
                            ok = 1;
                            have_find = 1;
                            cout << "     250" << endl;
                            break;
                        }
                    }
                    if(!have_find)
                        cout << "     550" << endl;
                }
            }
            if(ok){
                cout << "     DATA" << endl;
                cout << "     354" << endl;
                for(int z = 0;z < ret2 ; z++)
                    cout << "     " << data[z] << endl;
                cout << "     ." << endl;
                cout << "     250" << endl;
            }
            cout << "     QUIT" << endl;
            cout << "     221" << endl;
        }
    }
    return true;
}
int main(){
    GetMAT();
    while(SendEmail());
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值