题解 | 小红背单词

小红背单词

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;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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