Codeforces--4C--Registration system

题目描述:
Harry Potter is on a mission to destroy You-Know-Who’s Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle’s diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.

He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.

Formally, for a name si in the i-th line, output “YES” (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output “NO” (without quotes).
输入描述:
First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list.

Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
输出描述:
Output n lines each containing either “YES” or “NO” (without quotes), depending on whether this string was already present in the stream or not.

You can print each letter in any case (upper or lower).
输入:
6
tom
lucius
ginny
harry
ginny
harry
3
a
a
a
输出:
NO
NO
NO
NO
YES
YES
NO
YES
YES
题意:
输入一个字符串,如果没有输入过就输出OK,否则输出字符串和它的数字。
题解
map
代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        map<string,int> mp;
        mp.clear();
        string op;
        for(int i = 1; i <= n; i ++){
            cin>>op;
            if(mp[op] == 0) cout<<"OK"<<endl;
            else{
                cout<<op<<mp[op]<<endl;
            }
            mp[op] ++;
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值