问题不难,就是存储手机中好友的姓名,若有收到某个好友的祝福短信,则“人数”减一,因为该人会在收到短信的时候随即回复信息,不再考虑; 陌生人的短信不需考虑
#include<iostream>
#include<string>
#include<set>
#include<cctype>
using namespace std;
int main()
{
int friNum;//朋友人数
while(cin >> friNum && friNum != 0)
{
int resNum;//收到信息数
cin >> resNum;
string name;//储存人名
set<string> friSet;
for(int i = 0; i < friNum; i++)
{
cin >> name;
for(int j = 0; j < name.length(); j++)//统一为小写
{
name[j] = tolower(name[j]);
}
friSet.insert(name);
}
//输入收到信息的人名信息并在好友中寻找
set<string>::iterator itSet;
for(int i = 0; i < resNum; i++)
{
cin >> name;
for(int j = 0; j < name.length(); j++)
{
name[j] = tolower(name[j]);
}
itSet = friSet.find(name);
if(itSet != friSet.end())//有找到
{
friSet.erase(itSet);
}
else//没有找到
;//因为就算是陌生人发来的他也会立刻回复
}
cout << friSet.size() << endl;
}
}