zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Kafka Kerberos客户端访问
    Kafka Kerberos服务端配置
    Centos安装Kafka
    aaaaaaaaaaaa
    Kafka队列消息和发布订阅消息
    RabbitMQ概念
    RabbitMQ使用
    windows下安装Erlang
    RabbitMQ简介
    Flume简介
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4617175.html
Copyright © 2011-2022 走看看