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
/**
分析:该题是,判断一个新输入字符串是否属于原先字符串序列
①"不属于" : 打印"OK"表示插入成功
②"属于" : 判断是第几次出现该串(序列号) --> 并打印:"该串" + 序列号
方法:map <string, int>
模板:
map <string, int> my_map;
pair <map <string, int> :: iterator, bool> pr; pr = my_map.insert (map <string, int> (str, 0));
if (!pr.second)
{
++ my_map [str];
cout <<str <<my_map [str] <<endl;
}
else
{
cout <<"OK" <<endl;
}
**/

C/C++代码实现:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <stack>
#include <queue>
#include <map> using namespace std; int N; string str; int main () {
~scanf ("%d", &N);
map <string, int> my_map;
pair <map <string, int> :: iterator, bool> pr; while (N --) {
cin >>str;
pr = my_map.insert (pair <string, int> (str, ));
if (!pr.second) { // 插入失败
my_map [str] ++;
cout <<str <<my_map [str] <<endl;
} else {
printf ("OK\n");
}
}
return ;
}

nyoj 991 Registration system (map)的更多相关文章

  1. nyoj 911 Registration system(map)

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

  2. nyoj Registration system

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

  3. (用了map) Registration system

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

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

  5. ACM Registration system

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

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

  7. CodeForces-4C Registration system

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

  8. codeforces Registration system

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

  9. System.map文件【转】

    转自:http://blog.csdn.net/david104/article/details/7194185 当运行GNU链接器gld(ld)时若使用了"-M"选项,或者使用n ...

随机推荐

  1. JavaScript实现百度搜索页面

    JavaScript实现百度搜索页面 HTML <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...

  2. DeCantor Expansion (逆康托展开)

    Background\text{Background}Background The \text{The }The Listen&Say Test will be hold on May 11, ...

  3. mysql连接方法

    一.MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格) mysql -h localhost -u root -p123或mysql -u ...

  4. [洛谷P2425]小红帽的回文数

    原题传送门 这道题需要枚举.如果直接枚举会$TLE$. 考虑进制的转换:对于$> x$的进制下,一定是回文数 回文长度$2$位:设每一位为$i$,进制为$x$,则该数为$i*x+i$.反之,如果 ...

  5. 2019.10.29 CSP%您赛第四场t2

    我太菜了我竟然不会分层图最短路 ____________________________________________________________________________________ ...

  6. 处理 Could not find a 'KafkaClient' entry in the JAAS configuration. System property 'java.security.auth.login.config' is

    场景 某监控进程需要访问多个集群的Kafka INFO - org.apache.kafka.common.KafkaException: Failed to construct kafka cons ...

  7. redis入门(二)

    目录 redis入门(二) 前言 持久化 RDB AOF 持久化文件加载 高可用 哨兵 流程 安装部署 配置技巧 集群 原理 集群搭建 参考文档 redis入门(二) 前言 在redis入门(一)简单 ...

  8. Django之多对多表之through第三张表之InlineModelAdmin后台内嵌

    话不多说,来看表结构 这里有两个表,一个是阶段表,一个是老师表,一个老师可以带多个阶段,一个阶段也可以由多个老师带,所以是多对多关系 # 阶段表 class Stage(models.Model): ...

  9. fenby C语言 P9

    逻辑运算 真1 假0 &&与 真&&真为真 真&&假为假 假&&真为假 假&&假为假 ||或 真||真为真 真||假为真 ...

  10. spring-boot-plus是易于使用,快速,高效,功能丰富,开源的spring boot 脚手架.

    Everyone can develop projects independently, quickly and efficiently! spring-boot-plus是一套集成spring bo ...