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. delphi XE3解析JSON数据

    测试数据如下: Memo1.text中的数据: { "date":"周二(今天, 实时:12℃)", "dayPictureUrl":&qu ...

  2. JAVA动态性之一一反射机制reflection

    package com.bjsxt.reflection.test.bean; public class User { private int id; private int age; private ...

  3. MVC 发布到IIS中的配置方法

    MVC 发布到IIS中的配置方法  http://msdn.microsoft.com/zh-cn/library/gg703322(v=vs.98).aspx

  4. mysql 导出sql结果成csv文件

    mysql -uroot -p -e "use database;sql语句:" > a.csv 举例: mysql -uroot -p -e "use main; ...

  5. numpy.unpackbits()

    numpy.unpackbits numpy.unpackbits(myarray, axis=None) Unpacks elements of a uint8 array into a binar ...

  6. Codeforces Beta Round#2

    Codeforces Beta Round#2 http://codeforces.com/contest/2 A 模拟题 #include<bits/stdc++.h> using na ...

  7. 解决mysql无法远程登陆问题

    解决这个问题的思路: 一.先确定能过3306端口 二.再检查授权Host是否存在 (新授权记得flush privileges;)   一 步骤 1.首先打开mysql的配置文件,找到这句话,注释掉. ...

  8. 帧动画 连续播放多张图片动画 以及ui动画 SoundPool

    drawable下有很多图片  可以 <?xml version="1.0" encoding="utf-8"?> <animation-li ...

  9. nginx安装及基础配置(含jdk安装及配置)

    0.jdk安装配置 #下载相应的jdk软件包,然后解压安装,我这里包名称为:jdk-7u25-linux-x64.tar.gz tar -xzf jdk-7u25-linux-x64.tar.gz m ...

  10. win 下 apache 虚拟主机配置方式

    虚拟主机的配置在apache安装目录下/conf/extra/httpd-vhosts.conf文件中,需要在/conf/httpd.conf中开启. LoadModule vhost_alias_m ...