字符串哈希

利用哈希表去重,统计不同字符串的个数

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int res=0; // 记录不同字符串的个数
    unordered_map<string,int>cnt; // 记录每个字符串是否已出现
    while(n--){
        string s;
        cin>>s;
        if(cnt[s]==0){ 
            cnt[s]++; // 标记为已出现
            res++; // 
            个数+1
        }
    }
    cout<<res;
    return 0;
}
全部评论

相关推荐

02-26 09:15
已编辑
蚌埠学院 golang
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务