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 ...
随机推荐
- 动画讲解TCP
前言 TCP 三次握手过程对于面试是必考的一个,所以不但要掌握 TCP 整个握手的过程,其中有些小细节也更受到面试官的青睐. 对于这部分掌握以及 TCP 的四次挥手,小鹿将会以动画的形式呈现给每个人, ...
- [JZOJ5775]【NOIP2008模拟】农夫约的假期
Description 在某国有一个叫农夫约的人,他养了很多羊,其中有两头名叫mm和hh,他们的歌声十分好听,被当地人称为“魔音”······ 农夫约也有自己的假期呀!他要去海边度假,然而mm和 ...
- gedit 外部工具——快捷运行
可快捷编译运行一些代码,适合新手使用. 配置如下. 快捷键:F5 保存:当前文档 输入:无 输出:无 使用范围:所有文档,所有语言 脚本如下. #!/bin/sh #author: srczhang# ...
- halcon学习方法小结及以后的学习计划
学了这么久的halcon,感觉还是没有摸到门路. 记录一下这么久以来经历过的学习阶段: 看冈萨雷斯<数字图像处理>这本书,使用halcon做练习. 我实际上只比较完整地看了这本书的形态学处 ...
- 02--Java Jshell的使用 最适合入门的Java教程
JShell JShell目标 Java Shell 工具(简称:JShell)是一个用于学习Java编程语言和构建Java代码原型的交互式工具.JShell是一个Read-Evaluate-Prin ...
- 入门了解Service Mesh + Istio?从本文开始
下周六,深圳,阔别已久的线下技术沙龙要和你见面啦! 现场有Rancher Labs研发经理demo刚刚发布的Rancher 2.3中的Istio.Windows容器.集群模板等功能及使用,还有k3s首 ...
- Spring 源码阅读之 深入理解 finishBeanFactoryInitialization
源码入口 上篇博文中我们看到了将Spring环境中的 BeanPostProcessor找出来,添加到BeanFactory中的beanPostProcessors中,统一维护,本片博文继续往下拓展, ...
- 百万年薪python之路 -- 装饰器进阶
本文链接:https://blog.csdn.net/xiemanR/article/details/72510885 一:函数装饰函数 def wrapFun(func): def inner(a, ...
- MyEclipse 2013配置JDBC连接mySQL||Tomcat 7.0 8.0 配置 JDBC |配置mysql-connector-java-5.1.16
MyEclipse->Preferences->MyEclipse->Severs->Intergated Sandbox->Myeclipse Tomcat 7(或者T ...
- requests+lxml+xpath爬取电影天堂
1.导入相应的包 import requests from lxml import etree 2.原始ur url="https://www.dytt8.net/html/gndy/dyz ...