Problem 1475 不同的单词.
思路
- 字符串数组存放输入的字符 + 映射储存该单词重复的个数
- 注意:大小写忽略不计,先同意吧每个字符串都转成小写再处理
笔记
#include<cctype>
isalnum()
isalpha()
isdigit() isxdigit()
isblank()
islower() isupper()
tolower() toupper()
- map相关
item = m.find(key)
遍历m寻找key,找到返回。m中不存在则返回m.end()
代码
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<cctype>
using namespace std;
map<string, int> m;
string words[1000];
int main(){
int n, count;
while(scanf("%d", &n)!=EOF){
for(int i=0; i<n; i++){
cin >> words[i];
for(int k=0; k<words[i].size(); k++)
words[i][k] = tolower(words[i][k]);
if(m.find(words[i])==m.end())
m[words[i]] = 0;
else
m[words[i]]++;
}
count = n;
for(int i=0; i<n; i++){
if(m[words[i]]!=0){
count -= m[words[i]];
m[words[i]] = 0;
}
}
printf("%d\n", count);
}
return 0;
}