一道比较水的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; }
814-The Letter Carrier's Rounds【模拟、STL、被坑了】
原文:http://blog.csdn.net/u013451221/article/details/44597427