• nyoj 911 Registration system(map)


    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.
    样例输入
    4
    abacaba
    acaba
    abacaba
    acab
    
    样例输出
    OK
    OK
    abacaba1
    OK
    可以用multiset或者multimap
    用map映照容器简单。
     1 #pragma warning(disable:4786)//忽略超长的一个警告,这个警告对程序没有影响,(map,set)
     2 #include <iostream>
     3 #include <map>
     4 #include <string>
     5 using namespace std;
     6 int main(){
     7     int n;
     8     string str;
     9     map<string, int> mp;
    10     cin >> n;
    11     while(n--){
    12         cin >> str;
    13         //键值没有str,则map[str] = 0;
    14         if(mp[str]){
    15             cout << str << mp[str] << endl;
    16         }else{
    17             cout << "OK" << endl;
    18         }
    19         mp[str]++;
    20         
    21     }
    22     return 0;
    23 }
     
  • 相关阅读:
    03server
    Storm介绍(一)
    storm总结
    Spring源码分析(七)扩展接口BeanPostProcessors源码分析
    技术大牛养成指南
    02装配bean
    02Activity
    maven构建项目
    IDEA使用
    从GIt上导出Maven项目
  • 原文地址:https://www.cnblogs.com/qinduanyinghua/p/6412503.html
Copyright © 2020-2023  润新知