Codeforces 4C Registration System

Source: Internet
Author: User

Registration SystemTime limit:5000msmemory limit:65536kbthis problem would be judged onCodeforces. Original id:4c
64-bit integer IO format: %i64d Java class name: (any)

A new e-mail Service "Berlandesk" is going to being opened in Berland on the near future. The site administration wants to launch their project as soon as possible, that's why they ask for 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 hisName. If such aname does not exist in the system database, it's 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-a new use R name, sends it to the user as a prompt and also inserts the prompt into the Databas E. The new name is formed by the following rule. Numbers, starting with 1, is appended one after another to name  (name1,name2, ...), among these numbers the Least  i  is found so that name I  does not yet exist in the database.

Input

The first line contains number n (1≤ n ≤105). The following n lines contain the requests to the system. Each request was a non-empty line, and consists of not more than characters, which was all lowercase Latin.

Output

Print n lines, which is 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.

Sample InputInput
4
Abacaba
Acaba
Abacaba
Acab
Output
Ok
Ok
Abacaba1
Ok
Input
6
First
First
Second
Second
Third
Third
Output
Ok
First1
Ok
Second1
Ok
Third1
SourceCodeforces Beta Round #4 (Div. 2 only) Problem solving: water and water more enjoyable
1#include <bits/stdc++.h>2 using namespacestd;3map<string,int>MP;4 intN;5 stringstr;6 intMain () {7Ios::sync_with_stdio (false);8 mp.clear ();9Cin>>N;Ten      while(n--) { OneCin>>str; A         if(Mp[str]) cout<<str<< (mp[str]++) <<Endl; -         Else { -mp[str]++; thecout<<"OK"<<Endl; -         } -     } -     return 0; +}
View Code

Codeforces 4C Registration System

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.