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. 提升开发技能:10个高级的JavaScript技巧

    前言 在这个快速发展的数字时代,JavaScript作为一种广泛应用的编程语言,其重要性愈发凸显.为了在竞争激烈的开发领域中保持竞争力,不断提升自己的技能是至关重要的.本文小编将您介绍10个高级的Ja ...

  2. 如何使用Tampermonkey开发并使用一个浏览器脚本

    准备工作 简介 Tampermonkey 是一款强大的浏览器扩展,它允许您定制网页的行为,改变和优化网页的展示方式或者功能以满足个人需求.通过编写自定义脚本,您可以实现许多有趣的功能,从自动化任务到改 ...

  3. 畅捷通T+与道一云对接集成报销信息列表连通凭证创建

    畅捷通T+与道一云对接集成获取报销信息列表连通凭证创建 数据源系统:道一云 在道一云坚实的技术基础上,道一云推出全新升级的2.0产品矩阵,分别是低码平台.智能门户.场景应用.基于云原生底座,为企业提供 ...

  4. 【Android】做一个简单的每日打卡app-day01【还没做好】

    任务: 第一阶段目标: 1.用户注册:用户注册信息包括用户ID(学号).用户名(姓名),手机号码,用户单位(班级),用户班级四项基本信息,用户第一次注册后,用户姓名不用每次输入 . 2.每日总结打卡: ...

  5. JavaWeb开发-CSS基础

    2.CSS层叠样式表基本语法 层叠样式表,用来控制页面的样式 (1)CSS的三种引入方式 内部样式表:适合学习使用,将CSS代码写在style标签里面,style标签嵌套在title里 外部样式表:开 ...

  6. CTT2023 邮寄

    从广州被邮寄到了苏州.还有点感冒有点咳嗽,体温 37 度.还是来了. Day 0 清早坐 xp 的车,早上坐飞机,中午坐高铁,下午坐大巴,风尘仆仆地赶到了苏州. 飞机上有一套省选题要验,看了两眼,T1 ...

  7. ORCAD BOM制作

    1.导出BOM增加/TPCB Footpint和/tOptionnal 选项 2.器件选焊的optionnal设置/X符号, 3.导出BOM后选择/X的,删除,不出现加工的BOM中

  8. [NOI online2022提高B] 讨论

    题目描述 有 \(n\) 个人正在打模拟赛,模拟赛有 \(n\) 道题目. 有两人都会的题目并且没有人会的题目包含另一个人时,两者之间才会讨论. (定义第 ii 个人会的题目的集合为 \(S_i\) ...

  9. Java中“100==100”为true,而"1000==1000"为false?

    前言 今天跟大家聊一个有趣的话题,在Java中两个Integer对象做比较时,会产生意想不到的结果. 例如: Integer a = 100; Integer b = 100; System.out. ...

  10. 如何通过port-forward命令在本地访问 k8s 集群服务

    公众号「架构成长指南」,专注于生产实践.云原生.分布式系统.大数据技术分享 概述 在我们访问k8s中的pod服务时,一般通过node port映射pod端口进行访问,还有一种是通过ingress或者i ...