题意
模拟mta发送邮件
模拟的我头皮发麻
记录
有个挺骚的操作记下来了, 有点意思
string text;
while(getline(cin, s) && s[0] != '*')
text += " " + s + "\n";
AC代码
#include
#include
#include
#include
#include
#include
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;
}