CF4C.Registration system

普及-

通过率:0%

时间限制:5.00s

内存限制:64MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 name_i_ does not yet exist in the database.

一种新的电子邮件服务“Berlandesk”即将在贝尔兰(Berland)上线。网站管理方希望尽快启动该项目,因此请求你的帮助。你需要实现一个网站注册系统的原型。该系统应按以下规则工作:

每次有新用户希望注册时,他向系统发送一条包含其姓名的请求。如果该姓名尚未存在于系统数据库中,则将其插入数据库,并向用户返回响应 OK,以确认注册成功。如果该姓名已存在于系统数据库中,则系统将生成一个新的用户名,将其作为提示发送给用户,同时将该提示也插入数据库。新用户名的生成规则如下:将从 1 开始的数字依次附加到原姓名之后(即 name1、name2、…),从中找出最小的整数 $ i $,使得 name_i 尚未存在于数据库中。

输入格式

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.

第一行包含一个数字 nn(1≤n≤1051 \leq n \leq 10^5)。接下来的 nn 行表示对系统的请求。每个请求是一行非空字符串,且长度不超过 32 个字符,所有字符均为小写拉丁字母。

输出格式

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.

输出 n 行,即系统对请求的响应:若注册成功,则输出 OK;若所请求的用户名已被占用,则输出提示信息(含新用户名)。

输入输出样例

  • 输入#1

    4
    abacaba
    acaba
    abacaba
    acab

    输出#1

    OK
    OK
    abacaba1
    OK
  • 输入#2

    6
    first
    first
    second
    second
    third
    third

    输出#2

    OK
    first1
    OK
    second1
    OK
    third1

输入解题思路,AI测评打分。不知道怎么写?

首页