# include<iostream>
# include<map>
# include<set>
# include<string>
# include<vector>
using namespace std;
void parse_add(const string& s, string& user, string& mta)//对数据进行处理的函数
{
int k = s.find('@');
user = s.substr(0, k);
mta = s.substr(k + 1);
}
int main(void)
{
int k;
string s, t, user1, mta1, user2, mta2;
set<string>addr;
//输入mta将其进行,存储
while (cin >> s && s != "*")//结束所有的发送操作
{
cin >> s >> k;
while (k--)
{
cin >> t;
addr.insert(t + "@" + s);
}
}//为后面进行标记,标记处收件人
while (cin >> s && s != "*")
{
parse_add(s, user1, mta1);//发件人
vector<string>mta;//储存所有需要用到的容器,不要重复的
map<string, vector<string>>dest;//按照mta对人名和mta进行存储
set<string>vis;//避免完全相同的地址和收件人
while (cin >> t && t != "*")
{
parse_add(t, user2, mta2);
if (vis.count(t))
continue;//count 的是t
vis.insert(t);
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++)
{
string mta2 = mta[i];
vector<string>users = dest[mta2];
cout << "Connection between " << mta1 << " and " << mta2 << endl;
cout << " HELO " << mta1 << endl;
cout << " 250\n";
cout << " MAIL FROM:<" << s << ">\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";
cout << " 354\n";
cout << data;
cout << " .\n";
cout << " 250\n";
}
cout << " QUIT\n";
cout << " 221\n";
}
}
return 0;
}
本题核心之处在于对map.vector容器嵌套容器的使用,还有很多oj上交题必须的细节,感觉写完之后收获很大