codeforces Registration system
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 32 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
6
first
first
second
second
third
third
OK
first1
OK
second1
OK
third1 用的map做的。
#include <bits/stdc++.h>
using namespace std;
map<string, int> c;
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(0);
c.clear();
int t,i;
char s[];
scanf("%d ",&t);
for(i=;i<=t;i++)
{
cin>>s;
c[s]++;
auto p=c.find(s);
if(p->second>) cout<<p->first<<p->second-<<endl;
else cout<<"OK"<<endl;
}
return ;
}
codeforces Registration system的更多相关文章
- 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 ...
- 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 ...
- (用了map) Registration system
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93241#problem/C (654123) http://codeforces.com ...
- ACM Registration system
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- c题 Registration system
Description A new e-mail service "Berlandesk" is going to be opened in Berland in the near ...
- CodeForces-4C Registration system
// Registration system.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include <iostream> # ...
- nyoj Registration system
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- Registration system
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 A new e-mail service "Berlandesk&q ...
- nyoj 911 Registration system(map)
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
随机推荐
- jenkins 执行shell命令出错command not found 和No such file or directory
[root@localhost usr]# sh test.sh command not found -bash: cd: usr: No such file or directory 这里碰到了一个 ...
- C#继承的多态性
C#继承的多态性 当一个类A派生出新类B时,这个基类A在新类B中可以表现为不同的类型:用作它自己的类型.基类型,或者在实现接口时用作接口类型,我们将这种情况称为多态性. C#中的每种类型都是多态性的, ...
- javaScript校验图片大小、格式
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...
- AMD、CMD、CommonJs和ES6对比
一.AMD(异步模块定义) AMD(异步模块定义)是RequireJS在推广过程中对模块定义的规范化产出.AMD是一个概念,RequireJs是对这个概念的实现.比如javascript语言是对ECM ...
- 什么是 BIND 变量?
变量绑定会使联机事务处理过程(OLTP)系统数据库中的SQL执行速度飞快,内存效率极高:不使用绑定变量可能会使OLTP数据库不堪重负,资源被SQL解析严重耗尽,系统运行缓慢. 当一个用户与数据库建立连 ...
- jQuery选择器与事件学习笔记
层次选择器: $("div li")获取div下的所有li元素(后代.子.子的子......) $("div>li")获取div下的直接li子元素. ...
- IDEA搭建SSM出现的一些错误
下面是我这几天整合SpringMVC+Spring+MyBatis框架遇到的一些问题 ,在这里总结一下: 1:HTTP Status 500 - Request processing failed; ...
- linux下Tomcat配置提示权限不够解决办法
在终端输入命令 sudo chmod -R 777 /opt/Tomcat,那么Tomcat文件夹和它下面的所有子文件夹的属性都变成了777(读/写/执行权限)
- (转)数据库老兵:NewSQL才是未来
编者按:在数据库技术领域,Michael Stonebraker几乎是无人不知无人不晓的人物.现年70岁的Stonebraker不仅是Ingres和PostgreSQL的创始人,同时在Informix ...
- .NET领域驱动设计系列(12)
[.NET领域驱动设计实战系列]专题十一:.NET 领域驱动设计实战系列总结 摘要: 一.引用 其实在去年本人已经看过很多关于领域驱动设计的书籍了,包括Microsoft .NET企业级应用框架设计. ...