NYOJ 991 Registration systemz(map)
来源:互联网 发布:无法启用网络发现 编辑:程序博客网 时间:2024/06/05 21:14
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.
- 样例输入
4abacabaacabaabacabaacab
- 样例输出
OKOKabacaba1OK
题意:就是看给的的字符串有重复的没,没有输出OK,如果重复就输出输出这个字符串然后再输出出现的次数-1,。
上代码:
#include<map>#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>#include<sstream>#include<set>#include<stack>#define id 3.1415926535//这个是没用的using namespace std;int main(){ int n; scanf("%d",&n); map<string,int>p;//建一个容器p for(int i=1; i<=n; i++) { string s; cin>>s; p[s]++;//字符串出现的次数 if(p[s]==1)//出现一次输出OK { printf("OK\n"); } else { cout<<s<<p[s]-1<<endl;//否则的话输出字符串和次数减一 } } return 0;}
- NYOJ 991 Registration systemz(map)
- NYOJ 991 Registration system(map容器)
- NYOJ 991 Registration system(map简单应用)
- NYOJ 题目991 Registration system(set)
- nyoj-991-Registration system
- NYOJ 991 Registration system
- NYOJ 991 Registration system
- NYOJ---题目991Registration system
- 【南理oj】991 - Registration system(STL - map & string)
- NYOJ--Registration system
- NYOJ Registration system
- nyoj991-Registration system(map)
- CodeForces 4C Registration system(字符串处理 | map)
- 【CodeForce】 4C Registration system(map乱搞)
- cf 4c Registration system (map学习)
- 4C - Registration System【map】
- Codeforces 4C-Registration system(map)
- Codeforces 4C Registration system (map)
- xlrd xlwt xlutils安装出错解决方案
- style——基本使用
- linux的nohup命令的用法
- Java正则表达式
- Android 实现背景半透明
- NYOJ 991 Registration systemz(map)
- Android串口通信
- PHP调试时print_r ,var_dump的区别
- SIFT特征
- Oracle中Merge into ,亲测可行
- POJ 1222 开关问题高斯消元法
- CI静态化页面
- json_decode使用
- Java理论与实践:正确使用volatile变量 (r)