题解 | 小红背单词
小红背单词
https://www.nowcoder.com/practice/b3d0fa1c43c44e0580654cb93c1bfdb9
#include <iostream>
#include<string>
#include<unordered_map>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
unordered_map<string,int>count;
int cnt=0;
for(int i=0;i<n;i++){
string word;
cin>>word;
if(count[word]<cnt+1){
count[word]++;
if(count[word]==cnt+1){
cnt++;
count[word]=-2e5;
}
}
}
cout<<cnt<<endl;
return 0;
}
查看28道真题和解析