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. Windows10+Python+Yolov8+ONNX图片缺陷识别,并在原图中标记缺陷,有onnx模型则无需配置,无需训练。

    目录 一.训练自己数据集的YOLOv8模型 1.博主电脑配置 2.深度学习GPU环境配置 3.yolov8深度学习环境准备 4.准备数据集 二.Python+Onnx模型进行图像缺陷检测,并在原图中标 ...

  2. ABAP 自定义附件

    SWO1 关键字   *------------------------------------------------------------* REPORT ZTEST_CSW1. *TABLES ...

  3. Typora的安装与使用教程

    一.安装 1.下载 下载地址:Typora 官方中文站 二.安装 1.无脑下一步即可. 三.使用教程 1.Typora系统设置 一般导出使用PDF文件比较好,性价比比较高. 2.其他设置 以下所有设置 ...

  4. 一次elasticsearch 查询瞬间超时案例分析

    大家好,我是蓝胖子,有段时间没有做性能分析案例讲解了,正好前两天碰到一个性能问题,今天就来对它探讨探讨. 问题背景 在晚上9点左右,刚从外面逛街回到家,就接到了电话报警(幸好前不久刚好把电话报警机制加 ...

  5. 写入数据或者通过EXCEl批量导入到数据库时报类型转换异常问题

    报错日志如下(此处我用的是达梦,实际MySQL和oracle也会有类似的问题): Cause: org.apache.ibatis.type.TypeException: Error setting ...

  6. Python给exe添加以管理员运行的属性

    需求 有些应用每次启动都需要用管理员权限运行,比如Python注入dll时,编辑器或cmd就需要以管理员权限运行,不然注入就会失败. 这篇文章用编程怎么修改配置实现打开某个软件都是使用管理员运行,就不 ...

  7. 一文读懂遗传算法(附python)

    几天前,我着手解决一个实际问题--大型超市销售问题.在使用了几个简单模型做了一些特征工程之后,我在排行榜上名列第 219 名. 虽然结果不错,但是我还是想做得更好.于是,我开始研究可以提高分数的优化方 ...

  8. 中企网安信息科技:基于数据化大屏的BI数据分析管理系统概述

    由华企网安总公司北京中企网安信息科技有限责任公司开发的<基于数据化大屏的BI数据分析管理系统>,获得国家版权局颁发的计算机软件著作权登记证书. 基于数据化大屏的BI数据分析管理系统利用大数 ...

  9. MySQL 数据目录

    MySQL 的数据目录 1. MySQL 的主要目录结构 方式1:通过命令搜索 find / -name mysql 方式2(推荐):通过查看配置文件获取目录结构 vim /etc/my.cnf (重 ...

  10. 文心一言 VS 讯飞星火 VS chatgpt (169)-- 算法导论13.2 2题

    二.用go语言,证明:在任何一棵有 n 个结点的二叉搜索树中,恰有 n-1种可能的旋转. 文心一言: 要证明在任何一棵有 n 个结点的二叉搜索树中,恰有 n-1 种可能的旋转,我们可以按照以下步骤逐步 ...