codefores 4C(统计出现过的次数)
来源:互联网 发布:四川旅游五天 知乎 编辑:程序博客网 时间:2024/05/21 08:59
Description
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.
Input
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 32 characters, which are all lowercase Latin letters.
Output
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.
Sample Input
4abacabaacabaabacabaacab
OKOKabacaba1OK
6firstfirstsecondsecondthirdthird
OKfirst1OKsecond1OKthird1
#include<stdio.h>#include<string.h>char a[100005][35],t[35];int main(){int n,s[100005];while(scanf("%d",&n)!=EOF){int f=0,i,j,k=0;getchar();memset(s,0,sizeof(s));for(i=0;i<n;i++){gets(t);for(j=0;j<k;j++)if(strcmp(t,a[j])==0)break;if(j==k){strcpy(a[k],t);s[k++]=1;printf("OK\n");}elseprintf("%s%d\n",t,s[j]++);}}return 0;}
map<string, int> maps;int main() {int n;cin>> n;string s;while(n--) {cin>> s;maps[s] ++;if(maps[s] > 1) cout<< s<< maps[s] - 1<< endl;else cout<< "OK"<< endl;}return 0; }
- codefores 4C(统计出现过的次数)
- 学着用map统计字符出现的次数,也可以用来标记字符是否出现过
- C统计1-49的数字出现的次数
- C语言统计子字符串出现的次数
- 一个用来统计c语言关键字出现次数的程序
- C语言程序设计语言统计字符出现的次数
- 统计输入C语言关键字的出现次数
- C语言—统计字符串出现次数最多的字母
- 统计C语言代码中常见关键字出现的次数
- C语言 字符串 统计字串子母串出现的次数
- 统计出现字符的次数
- 统计字符串出现的次数
- 字符串的出现次数统计
- 统计字符串出现的次数
- 电话号码出现的次数统计
- 统计字符串出现的次数
- 统计空格出现的次数
- 统计单词出现的次数
- Linux之父炮轰C++:糟糕程序员的垃圾语言
- 希望有懂经济的共同完成开源项目
- TestJDBC(22)
- 十六周上机任务(指来指去)
- 罗永浩 我的奋斗 摘抄
- codefores 4C(统计出现过的次数)
- C++实现IE缓存迭代器
- 从字符设备驱动浅析linux内核设计与实现
- 《那些年啊,那些事——一个程序员的奋斗史》——126
- Java模拟Post 提交表单数据
- 入门经典 第七章 7.2.1 生成1到N的排列
- 全局变量与头文件
- spring3.1.0 jar包详解说明
- 杭电Hd 2111