【FOJ】Problem 1475 不同的单词

Problem 1475 不同的单词.

思路

  • 字符串数组存放输入的字符 + 映射储存该单词重复的个数
  • 注意:大小写忽略不计,先同意吧每个字符串都转成小写再处理

笔记

  • cctype的常用函数(字符操作)
#include<cctype>
isalnum() //字母数字 
isalpha() //字母 大写1小写2不是0
isdigit() isxdigit() //数字 16进制数
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;
}
发布了46 篇原创文章 · 获赞 0 · 访问量 461

猜你喜欢

转载自blog.csdn.net/qq_44531167/article/details/105495298