nyoj Registration system
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
#include <iostream>
#include <map>
using namespace std;int main()
{
int n;
map<string,int> m;
cin>>n;
while(n--)
{
string s;
cin>>s;if(m[s])
cout<<s<<m[s]<<endl;
else
cout<<"OK"<<endl;
m[s]++;
}
return 0;
}map:数据的插入
在构造map容器后,我们就可以往里面插入数据了。这里讲三种插入数据的方法:
第一种:用insert函数插入pair数据
map<int, string> mapStudent;
mapStudent.insert(pair<int, string>(1,“student_one”));第二种:用insert函数插入value_type数据
map<int, string> mapStudent;
mapStudent.insert(map<int, string>::value_type (1,"student_one"));mapStudent.insert(make_pair(1, "student_one"));
第三种:用数组方式插入数据map<int, string> mapStudent;
mapStudent[1] = “student_one”;
mapStudent[2] = “student_two”;/*如果是
#include <map>
map<string, int> mapStudent;string s;
插入就用m[s]++;*/以上三种用法,虽然都可以实现数据的插入,但是它们是有区别的,当然了第一种和第二种在效果上是完成一样的,用insert函数插入数据,在数据的插入上涉及到集合的唯一性这个概念,即当map中有这个关键字时,insert操作是不能再插入这个数据的,但是用数组方式就不同了,它可以覆盖以前该关键字对应的值,即:如果当前存在该关键字,则覆盖改关键字的值,否则,以改关键字新建一个key—value;
nyoj Registration system的更多相关文章
- 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 ...
- 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> # ...
- (用了map) Registration system
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93241#problem/C (654123) http://codeforces.com ...
- codeforces Registration system
Registration system A new e-mail service "Berlandesk" is going to be opened in Berland in ...
- 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 ...
随机推荐
- 关于floyd 打印路径的问题
我们令 f[i][j] 表示从 i-->j的最短路上j前面的那个点. 显然初始化时 f[i][j]=i; (这样的话先判断一下i是否能到达j好点) 更新条件时,当发现通过点k能使最短 ...
- NOJ-1581 筷子 (线性DP)
题目大意:有n支筷子,已知长度,定义一双筷子的质量等于长度的平方差,问能否分成k双?若能,输出所有筷子的最小质量和. 题目分析:先将筷子按长度从小到大排序,定义状态dp(i,j)表示将前 i 支筷子分 ...
- Import Data from *.xlsx file to DB Table through OAF page(转)
Use Poi.jar Import Data from *.xlsx file to DB Table through OAF page Use Jxl.jar Import Data from ...
- OC Block(代码块)
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- 改变进程的优先级,nice,getpriority,setpriority
int getpriority(int which, int who);返回一组进程的优先级 参数which和who确定返回哪一组进程的优先级 The value which is one of PR ...
- VS2010创建动态链接库(DLL)的方法
1.第一步创建WIN32项目,选择DLL 2.第二步,创建你自己的DLL CPP文件和头文件,下面以两个简单的加减法函数为例子导出 然后编译生成即可.DLL文件在Debug或Release目录中 .d ...
- 快速切题 poj1129 Channel Allocation
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12334 Accepted: 63 ...
- bzoj3105
题解: 一道博弈论 题目要求取得最少,那么就是留下的最多 把石子从大到小排序 从打的开始刘 如果可以留,那么就留下了 如果留下了与前面留下来的异或后不为0,那么就可以留 代码: #include< ...
- SSH框架下载地址
Struts各版本下载地址: https://dist.apache.org/repos/dist/release/struts/ Spring各版本下载地址: http://repo.spring. ...
- 调用Nt函数内核模式切换问题
很久不写博客了,笔记大多记在电脑上在,以后整理好了再搬运上来吧. 今天记一下“进程内存管理器”这个小程序上遇到的一个问题——内核模式调用Nt*函数. 使用的是内核中的NtQueryVirtualMem ...