http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93241#problem/C (654123)

http://codeforces.com/problemset/problem/4/C

Registration system

Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

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
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std; #define N 21000 ///我也是醉了,map居然有这么大的好处 int main()
{
int n; while(scanf("%d", &n)!=EOF)
{
int i;
char s[]; map<string, int>a; for(i=; i<n; i++)
{
scanf("%s", s);
if(a[s])
printf("%s%d\n", s, a[s]);
else
printf("OK\n");
a[s]++;
}
}
return ;
}

(用了map) Registration system的更多相关文章

  1. Codeforces Beta Round #4 (Div. 2 Only) C. Registration system【裸hash/map】

    C. Registration system time limit per test 5 seconds memory limit per test 64 megabytes input standa ...

  2. nyoj 911 Registration system(map)

    Registration system 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 A new e-mail service "Berlandesk&q ...

  3. nyoj 991 Registration system (map)

    Registration system 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 A new e-mail service "Berlandesk&q ...

  4. ACM Registration system

    Registration system 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 A new e-mail service "Berlandesk&q ...

  5. Codeforces Beta Round #4 (Div. 2 Only) C. Registration system hash

    C. Registration system Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  6. CodeForces-4C Registration system

    // Registration system.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include <iostream> # ...

  7. nyoj Registration system

    Registration system 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 A new e-mail service "Berlandesk&q ...

  8. codeforces Registration system

     Registration system A new e-mail service "Berlandesk" is going to be opened in Berland in ...

  9. c题 Registration system

    Description A new e-mail service "Berlandesk" is going to be opened in Berland in the near ...

随机推荐

  1. ASP.NET MVC 项目文件夹结构

    首先,打开Visual Studio, 新建一个demo 项目的solution,选择 Blank Soution. 第二步,创建文件夹,按自己的需求创建.在这个Demo 中,我将创建4个文件夹. P ...

  2. IIS中利用ARR实现反向代理

    反向代理是什么,不了解的,请自行百度.本人也是最近才研究这个主题,简单的来说,利用这项技术可以实现负载均衡,安全控制等web应用中重要的功能,对于web应用来说这是个很基础,也很重要的技术,值得开发者 ...

  3. Ansible Galaxy

    命令行工具 ansible-galaxy命令与Ansible捆绑在一起,您可以使用它从Galaxy或直接从基于git的SCM安装角色. 您还可以使用它在Galaxy网站上创建新角色,删除角色或执行任务 ...

  4. Ubuntu 18.04上安装R及Rstudio

    安装R引用自:https://www.howtoing.com/how-to-install-r-on-ubuntu-18-04 安装Rstudio引用自:https://www.rstudio.co ...

  5. springmvc DispatchServlet初始化九大加载策略(一)

    由于篇幅较长,因此分三篇进行讲解: springmvc DispatchServlet初始化九大加载策略(一) springmvc DispatchServlet初始化九大加载策略(二) spring ...

  6. MD5摘要算法实现

    网上找到的实现md5函数代码,包括一个头文件md5.h和一个源文件md5.c,用下面的测试代码test.c测试通过,各文件依次如下: 头文件md5.h: #ifndef MD5_H #define M ...

  7. np.random.seed()

    124.np.random.seed()的作用 陈容喜 关注 2018.01.11 21:36 字数 3 阅读 4460评论 0喜欢 6 今天看到一段代码时遇到了np.random.seed(),搞不 ...

  8. 两数之和-数据结构设计 · Two Sum - Data structure design

    [抄题]: 设计b并实现一个 TwoSum 类.他需要支持以下操作:add 和 find.add -把这个数添加到内部的数据结构.find -是否存在任意一对数字之和等于这个值 [思维问题]: 不知道 ...

  9. 过滤输入htmlentities与htmlspecialchars用法

    过滤输入 (即来自所列数据源中的任何数据)是指,转义或删除不安全的字符.在数据到达应用的存储层之前,一定要过滤输入数据.这是第一道防线.假如网站的评论表单接收html,默认情况下 访客可以毫无阻拦地在 ...

  10. 观察者模式 DataObserver

    DatasetObserver是Observer的一个子类 针对于adapter设计的 当调用notifydatasetchanged的时候就会触发回调的方法 adapter.registerObse ...