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
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std; int main(){
int n;
cin >> n;
map<string,int> nameMap;
while(n--){
string str;
cin >>str;
if(nameMap.find(str)==nameMap.end()){
nameMap.insert(make_pair(str,));
cout<<"OK"<<endl;
}else{
nameMap[str]++;
cout<<str<<nameMap[str]<<endl;
}
}
}

ACM Registration system的更多相关文章

  1. (用了map) Registration system

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

  2. 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 ...

  3. c题 Registration system

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

  4. CodeForces-4C Registration system

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

  5. nyoj Registration system

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

  6. codeforces Registration system

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

  7. 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 ...

  8. Registration system

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

  9. nyoj 911 Registration system(map)

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

随机推荐

  1. Android Programming: Pushing the Limits -- Chapter 7:Android IPC -- ApiWrapper

    前面两片文章讲解了通过AIDL和Messenger两种方式实现Android IPC.而本文所讲的并不是第三种IPC方式,而是对前面两种方式进行封装,这样我们就不用直接把Aidl文件,java文件拷贝 ...

  2. gzip

    gzip -c 将输出写到标准输出上,并保留原文本 gzip * : 把当前目录中的每个文件压缩成.gz文件 [root@NB gzip]# ls mysql-bin. mysql-bin..tar ...

  3. Delphi线程的终止

    当线程对象的Execute()执行完毕,我们就认为此线程终止了.这时候,它会调用Delphi的一个标准例程EndThread(),这个例程再调用API函数ExitThread().由ExitThrea ...

  4. DES加密算法实现

    好久没写博客了,正好趁着实现网络工程与安全的DES算法的功夫,把代码发上来. DES的介绍可见:DES加密 原理不赘述了..实在太多,其实就是一个形式化算法,按部就班的实现就可以,只不过有些繁琐,我写 ...

  5. 对服务器的ftp端口进行修改

    对服务器的ftp端口进行了修改,把21端口改了,比如221端口,就这样用221连接的时候,连接登录成功,但打不开目录,为何,总结如下: 1.完成一个FTP的传输过程不仅仅只需要21一个端口,而是2个端 ...

  6. 使用.NET Framework的配置文件app.config

    在一般的项目中,为了使你的代码更加灵活,更方便调整,减少不必要的hard code,我们都在config中添加许多配置信息,一般可以选择.NET自带的配置文件形式app.config或者web项目中的 ...

  7. <转>WCF中出现死锁或者超时

    WCF回调中的死锁 一.服务器端死锁 对于如下服务: [ServiceContract(CallbackContract = typeof(INotify))] public class Downlo ...

  8. ImageSwitcher自定意效果+定时切换图片

    Activity实现 1 import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; ...

  9. HR外包系统 - 员工项目 薪资项目 考勤项目 -管理

    项目管理-包括员工项目 薪资项目 考勤项目 一 后台总公司定义项目-前台分公司选择项目,定义别名-分公司客户选择员工项目,定义别名 分公司下面-新建薪资类别-薪资类别下面选择要的薪资和考勤项目. 二 ...

  10. Effective C++ 之 Item 3:尽可能使用 const

    Effective C++ Chapter 1. 让自己习惯C++(Accustoming Yourself to C++) Item 3. 尽可能使用 const (Use const whenev ...