字符串哈希
利用哈希表去重,统计不同字符串的个数
#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;
}
查看25道真题和解析