题目地址:http://soj.me/1194
题目说名字是不区分大小写的,用map数据结构记录那个人有没有发短信给他,然后就可以很快搞定
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
int a, b;
while (cin >> a) {
if (!a)
break;
cin >> b;
string name[20001];
for (int i = 0; i < a; i++) {
string temp;
cin >> temp;
for (int j = 0; j < temp.length(); j++)
temp[j] = tolower(temp[j]);
name[i] = temp;
}
map<string, bool> nm;
for (int i = 0; i < b; i++) {
string temp;
cin >> temp;
for (int j = 0; j < temp.length(); j++)
temp[j] = tolower(temp[j]);
nm[temp] = true;
}
int count = 0;
for (int i = 0; i < a; i++)
if (!nm[name[i]])
count++;
cout << count << endl;
}
return 0;
}
本文介绍了一个简单的社交网络分析算法,通过使用C++实现,利用map数据结构来统计在一个虚拟社交网络中,哪些成员没有收到过特定的信息。该算法将所有用户名转换为小写以忽略大小写差异,并最终统计出未收到信息的用户数量。
1902

被折叠的 条评论
为什么被折叠?



