NYOJ 991 Registration systemz(map)

来源:互联网 发布:无法启用网络发现 编辑:程序博客网 时间:2024/06/05 21:14

Registration system

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描述

A new e-mail service "Berlandesk" is going to be opened in Berland in the near future.

 The site administration wants to launch their project as soon as possible, that's why they

 ask you to help. You're suggested to implement the prototype of site registration system. 

The system should work on the following principle.

Each time a new user wants to register, he sends to the system a request with his name.

 If such a name does not exist in the system database, it is inserted into the database, and 

the user gets the response OK, confirming the successful registration. If the name already 

exists in the system database, the system makes up a new user name, sends it to the user 

as a prompt and also inserts the prompt into the database. The new name is formed by the

 following rule. Numbers, starting with 1, are appended one after another to name (name1,

 name2, ...), among these numbers the least i is found so that namei does not yet exist in

 the database.


输入
The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 1000 characters, which are all lowercase Latin letters.
输出
Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
样例输入
4abacabaacabaabacabaacab
样例输出
OKOKabacaba1OK

题意:就是看给的的字符串有重复的没,没有输出OK,如果重复就输出输出这个字符串然后再输出出现的次数-1,。

上代码:

#include<map>#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>#include<sstream>#include<set>#include<stack>#define id 3.1415926535//这个是没用的using namespace std;int main(){    int n;    scanf("%d",&n);    map<string,int>p;//建一个容器p    for(int i=1; i<=n; i++)    {        string s;        cin>>s;        p[s]++;//字符串出现的次数        if(p[s]==1)//出现一次输出OK        {            printf("OK\n");        }        else        {            cout<<s<<p[s]-1<<endl;//否则的话输出字符串和次数减一        }    }    return 0;}


0 0