Sicily 1194 Message Flood

本文介绍了一个简单的社交网络分析算法,通过使用C++实现,利用map数据结构来统计在一个虚拟社交网络中,哪些成员没有收到过特定的信息。该算法将所有用户名转换为小写以忽略大小写差异,并最终统计出未收到信息的用户数量。

题目地址: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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值