(用了map) Registration system
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93241#problem/C (654123)
http://codeforces.com/problemset/problem/4/C
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
4
abacaba
acaba
abacaba
acab
OK
OK
abacaba1
OK
6
first
first
second
second
third
third
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的更多相关文章
- 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 ...
- nyoj 911 Registration system(map)
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- nyoj 991 Registration system (map)
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- ACM Registration system
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- 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-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 ...
- codeforces Registration system
Registration system A new e-mail service "Berlandesk" is going to be opened in Berland in ...
- c题 Registration system
Description A new e-mail service "Berlandesk" is going to be opened in Berland in the near ...
随机推荐
- denyhosts配置详解
DenyHosts官方网站为:http://denyhosts.sourceforge.net 用DenyHosts可以阻止试图猜测SSH登录口令,它会分析/var/log/secure等日志文件,当 ...
- js中常见的创建对象的方法
前两天好好的把高程对象那一块又读了下,顺便写点笔记.补一句:代码都测试过了,应该没有问题的.可以直接拿到控制台跑! 1.工厂模式 function person(name, age, job) { v ...
- fiddler 发送get请求
点击Composer 点击执行(Execute) \ 这里演示的是带cookie
- IPMS 元件实作
一.改用zg框架的jsp 1.引入表头和表尾jsp <%@ include file="../../jsp/menuHeader.jsp"%> <%@ inclu ...
- Centos 安装Mongo DB
NOSQL在很短的时间里使用人数据高涨,这不仅是它提出的一种新存储思想,更是因为它在对大数据做操作的效率,明显高于关系数据库 工具/原料 接入Internet的一台Centos计算机 下载安装文件 ...
- webdriver自动化脚本
1.需求如下: 启动火狐浏览器首先打开百度,等待3秒然后打开博客首页,等待2秒然后关闭浏览器 from selenium import webdriver from time import sleep ...
- NetworkStateReceiver的简单应用
一.网络状态接收者是一个广播接收者当网络状态发生改变时会收到网络状态改变的广播 本例当网络状态改变时会进行相应处理 例如当断网时会发出通知点击通知后 会打开网络设置界面 代码如下: package c ...
- ROS两种workspace :overlay rosbuild_ws->catkin_ws->ROS库,
概念 ROS里面有一系列概念,作为初学者,最先接触的概念无非是node, package和workspace. node node是ROS里面最小的执行单位,你可以把node看成是一个main函数,当 ...
- (转)innodb 多版本并发控制原理详解
转自:https://blog.csdn.net/aoxida/article/details/50689619 多版本并发控制技术已经被广泛运用于各大数据库系统中,如Oracle,MS SQL Se ...
- 面向对象设计模式纵横谈:Factory Method 工厂方法模式(笔记记录)
从耦合关系谈起 耦合关系直接决定着软件面对变化时的行为 -模块与模块之间的紧耦合使得软件面对变化时,相关模块都要随之更改 -模块与模块之间的松耦合使得软件面对变化时,一些模块更容易被替换或者更改,但其 ...