题目991Registration system

描述

Anewe-mailservice"Berlandesk"isgoingtobeopenedinBerlandinthenearfuture.

Thesiteadministrationwantstolaunchtheirprojectassoonaspossible,that’swhythey

askyoutohelp.You’resuggestedtoimplementtheprototypeofsiteregistrationsystem.

Thesystemshouldworkonthefollowingprinciple.

Eachtimeanewuserwantstoregister,hesendstothesystemarequestwithhisname.

Ifsuchanamedoesnotexistinthesystemdatabase,itisinsertedintothedatabase,and

theusergetstheresponseOK,confirmingthesuccessfulregistration.Ifthenamealready

existsinthesystemdatabase,thesystemmakesupanewusername,sendsittotheuser

asapromptandalsoinsertsthepromptintothedatabase.Thenewnameisformedbythe

followingrule.Numbers,startingwith1,areappendedoneafteranothertoname(name1,

name2,…),amongthesenumberstheleastiisfoundsothatnameidoesnotyetexistin

thedatabase.

输入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来源爱生活上传者TCM_张鹏

#include<iostream>#include<stdio.h>#include<map>#include<string>#include<string.h>using namespace std;int main(){map<string,int>mp;string s;int test;while(cin>>test){for(int i=0;i<test;i++){cin>>s;if(mp[s]==0){printf("OK\n");mp[s]++;}else{cout<<s<<mp[s]<<endl;mp[s]++;}}}return 0;}

,如果心胸不似海,又怎能有海一样的事业。

题目991Registration system

相关文章:

你感兴趣的文章:

标签云: