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 name i 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.

Examples

input

4
abacaba
acaba
abacaba
acab

output

OK
OK
abacaba1
OK

input

6
first
first
second
second
third
third

output

OK
first1
OK
second1
OK
third1

思路:这道题是一道映射题,name对应的有几个即可

#include<bits/stdc++.h>
using namespace std;
int main() {
//freopen("in.txt","r",stdin);
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t; cin >> t;
unordered_map<string, int>s; string str;//unordered_map 不进行排序优化时间,不过仅从900+ms减少到600+ms
while (t--) {
cin >> str;
s[str]++;
if (s[str] > 1)cout << str << s[str] - 1 << endl;
else cout << "OK" << endl;
}
}
//dalao的优化时间算法:154ms
#include<bits/stdc++.h>
using namespace std;
#define getchar_unlocked() _getchar_nolock()
template<typename T> inline bool sc(T& num) {
bool neg = 0; int c; num = 0;
while (c = getchar_unlocked(), c < 33) {
if (c == EOF) return false;
}
if (c == '-') {
neg = 1; c = getchar_unlocked();
}
for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48; if (neg) num *= -1; return true; }
template<typename T, typename ...Args> inline void sc(T& num, Args&...args) { bool neg = 0; int c; num = 0; while (c = getchar_unlocked(), c < 33) { ; } if (c == '-') { neg = 1; c = getchar_unlocked(); } for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48; if (neg) num *= -1; sc(args...); }
inline void getstr(string& str) {
str.clear(); char cur;
while (cur = getchar_unlocked(), cur < 33) { ; }
while (cur > 32) { str += cur; cur = getchar_unlocked(); }
} int32_t main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
sc(n);
unordered_map<string, int> arr;
string str;
for (int i = 0; i < n; i++)
{
getstr(str);
int r = arr[str]++;
if (!r)
{
cout << "OK\n";
}
else
{
cout << str << r << '\n';
}
} return 0;
}

Codeforce:4C. Registration system (映射)的更多相关文章

  1. (水题)Codeforces - 4C - Registration system

    https://codeforces.com/problemset/problem/4/C 用来哈希的一道题目,用map也可以强行过,但是性能慢了6倍,说明是在字符串比较的时候花费了接近6倍的时间. ...

  2. (用了map) Registration system

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93241#problem/C (654123) http://codeforces.com ...

  3. ACM Registration system

    Registration system 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 A new e-mail service "Berlandesk&q ...

  4. 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 ...

  5. c题 Registration system

    Description A new e-mail service "Berlandesk" is going to be opened in Berland in the near ...

  6. CodeForces-4C Registration system

    // Registration system.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include <iostream> # ...

  7. nyoj Registration system

    Registration system 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 A new e-mail service "Berlandesk&q ...

  8. codeforces Registration system

     Registration system A new e-mail service "Berlandesk" is going to be opened in Berland in ...

  9. 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 ...

  10. Registration system

    Registration system 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 A new e-mail service "Berlandesk&q ...

随机推荐

  1. 阿里云轻量服务器上编译安装docker trojan时报错 fatal error: Killed signal terminated program cc1plus compilation

    轻量服务器编译安装docker trojan时报错   72%时 通过以下操作解决,和编译其他软件类似,是内存不足引起的 编译安装swoole的时候报错 fatal error: Killed sig ...

  2. Vs code创建项目教程

    1.首先,vscode本身没有新建项目的选项,所以要先创建一个空的文件夹. 2.然后打开vscode,再在vscode里面打开文件夹,这样才可以创建项目. 3.选择一个空文件夹. 4.Ctrl+shi ...

  3. [THUPC2022 决赛] rsraogps

    [THUPC2022 决赛] rsraogps 题目描述 给序列 \(a_1,\dots,a_n\),\(b_1,\dots,b_n\),\(c_1,\dots,c_n\), 定义区间 \([l,r] ...

  4. 数字孪生和GIS融合后能够为城市交通带来哪些便利?

    数字孪生和GIS的融合对于城市交通领域带来了诸多便利,从智能交通管理到出行体验的提升,为城市交通带来了全新的发展机遇. 首先,数字孪生技术与GIS的结合可以实现智能交通管理.通过GIS建立城市交通网络 ...

  5. 【分享】推荐一个非常好用的redis远程连接工具

    推荐一个非常好用的redis远程连接工具 蓝奏云地址 https://wwsi.lanzoum.com/ig7xZ0xspf0h 密码:4vnz 二维码:

  6. Windows系统修复(System Update Readiness Tool、SFC模式、DISM命令)可解决系统更新问题。

    安装System Update Readiness Tool 提供此更新是因为在 Windows servicing store 中发现了不一致,这可能会影响将来成功安装更新.service pack ...

  7. JavaFx之横向布局左右两侧对齐(十九)

    JavaFx之横向布局左右两侧对齐(十九) 横向布局HBox在子节点A.B中添加<HBox HBox.hgrow="ALWAYS"></HBox> 即可做到 ...

  8. ubuntu中vim乱码以及执行shell脚本时出现乱码

    vim打开文件中文出现乱码情况,可以参考如下办法: 在vim /usr/share/vim/vimrc文件末尾中加入 (这个vimrc文件是Vim 的系统级配置文件.文档.插件.语法高亮定义.颜色方案 ...

  9. 如何使用ffmpeg转换图片格式

    ffmpeg简介与图片格式介绍 windows安装ffmpeg,从如下网站下载release版本 https://www.gyan.dev/ffmpeg/builds/ ffmpeg 6.1版本仍然不 ...

  10. 监控cpu高的进程shell

    #!/bin/bash while [ 1 ]do ps aux|awk '{if($3>10){print $3" => "$0}}' sleep 0.5sdone