nyoj 991 Registration system (map)
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 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)的更多相关文章
- nyoj 911 Registration system(map)
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- nyoj Registration system
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- (用了map) Registration system
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93241#problem/C (654123) http://codeforces.com ...
- 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 ...
- 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> # ...
- codeforces Registration system
Registration system A new e-mail service "Berlandesk" is going to be opened in Berland in ...
- System.map文件【转】
转自:http://blog.csdn.net/david104/article/details/7194185 当运行GNU链接器gld(ld)时若使用了"-M"选项,或者使用n ...
随机推荐
- Logstash 入门
一.简介 Logstash 是开源的服务器端数据处理管道,支持从不同来源采集数据,装换数据,并将数据发送到不同的存储库中. Logstash 项目诞生于 2009 年 8 月 2 日.其作者是世界著名 ...
- 在Python中,输出格式:%d , %6d , %-6d, %06d , %.6f的一些区分
和C/C++编程语言一样 %d 普通的整数输出 i = 1 sum = 0 while i <= 100: sum += i i += 1 print("1到100的和为:%d&quo ...
- 使用 git bisect 定位你的 BUG
Git 是开发者的好帮手,今天跟大家分享的是用 git bisect 来找到你代码中的 bad commit . 背景 你可能遇到过这种情况, 昨天下班前把模块开发完了, 单元测试验证通过, git ...
- 数据结构(二十七)Huffman树和Huffman编码
Huffman树是一种在编码技术方面得到广泛应用的二叉树,它也是一种最优二叉树. 一.霍夫曼树的基本概念 1.结点的路径和结点的路径长度:结点间的路径是指从一个结点到另一个结点所经历的结点和分支序列. ...
- Security整合spring boot
Security整合spring boot 1.基础概念 Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在Spri ...
- python pytesseract使用
正确使用方法 1.tesseract-orc安装 tesseract-ocr-setup-3.05.00dev.exe下载 2.pytesseract pip install pytesseract ...
- Python3 下的输出字符控制
最近在使用 python3 进行爬虫的时候,出现了令人窒息的,只会在 python2 中遇到的,没想到在 python3 还能碰见的输出编码问题,报错如下: UnicodeEncodeError: ' ...
- ie浏览器兼容性的入门解决方案
IE浏览器的兼容性素来是令人头疼的问题,大名鼎鼎的FUCK-IE不是浪得虚名的. 这里使用的解决方案是HACK,具体原理就是针对不同的浏览器写不同的HTML.CSS样式,从而使各种浏览器达到一致的渲染 ...
- Java学习总结之方法重载和方法重写
在学习方法的阶段我学习了方法重载(Overload),而在学习面向对象三大特性之继承的时候我又学习了方法重写(Override). 概念: 方法重载:在同一个类中,允许存在一个以上的同名方法,只要 ...
- P2893 [USACO08FEB]修路
直入主题. 农夫约翰想改造一条路,原来的路的每一段海拔是Ai,修理后是Bi花费|A_i–B_i|.我们要求修好的路是单调不升或者单调不降的.求最小花费. 数据范围:n<=2000,0≤ Ai ≤ ...