• CodeForces 4C Registration system


    Registration system

    Time Limit: 5000ms
    Memory Limit: 65536KB
    This problem will be judged on CodeForces. Original ID: 4C
    64-bit integer IO format: %I64d      Java class name: (Any)
     

    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.

     

    Input

    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 32 characters, which are all lowercase Latin letters.

     

    Output

    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.

     

    Sample Input

    Input
    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

    Source

     
    解题:水水更开心
     
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 map<string,int>mp;
     4 int n;
     5 string str;
     6 int main() {
     7     ios::sync_with_stdio(false);
     8     mp.clear();
     9    cin>>n;
    10     while(n--) {
    11         cin>>str;
    12         if(mp[str]) cout<<str<<(mp[str]++)<<endl;
    13         else {
    14             mp[str]++;
    15             cout<<"OK"<<endl;
    16         }
    17     }
    18     return 0;
    19 }
    View Code
  • 相关阅读:
    WebUploader在IE9中文件选择按钮点击没反应
    nagios二次开发(四)---nagios监控原理和nagios架构简介
    nagios二次开发(三)---nagiosql架构简介
    nagios二次开发(二)---nagios和nagiosql合并与取舍
    Icinga快速安装与配置
    shell-自动更改LINUX服务器IP
    nginx环境下配置nagios-关于nagios配置文件nginx.conf
    nginx环境下配置nagiosQL-关于nagiosql配置文件
    nginx环境下配置nagios-关于start_perl_cgi.sh
    Scala学习(八)---Scala继承
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4617175.html
Copyright © 2020-2023  润新知