codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

4C.md (1802B)


      1 Source: https://codeforces.com/problemset/problem/4/C
      2 
      3 C. Registration system
      4 
      5 time limit per test
      6 
      7 5 seconds
      8 
      9 memory limit per test
     10 
     11 64 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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.
     22 
     23 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 name*i* does not yet exist in the database.
     24 
     25 Input
     26 
     27 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.
     28 
     29 Output
     30 
     31 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.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 4  
     39 abacaba  
     40 acaba  
     41 abacaba  
     42 acab
     43 ```
     44 
     45 Output
     46 
     47 ```
     48 OK  
     49 OK  
     50 abacaba1  
     51 OK
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 6  
     58 first  
     59 first  
     60 second  
     61 second  
     62 third  
     63 third
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 OK  
     70 first1  
     71 OK  
     72 second1  
     73 OK  
     74 third1
     75 ```