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. 23C新特性:True Cache的介绍

    我们的文章会在微信公众号"Oracle恢复实录"和博客网站"https://www.cnblogs.com/www-htz-pw/" 同步更新 ,欢迎关注收藏, ...

  2. Vue3+Vite+ElementPlus管理系统常见问题

    本文本记录了使用 Vue3+Vite+ElementPlus 从0开始搭建一个前端工程会面临的常见问题,没有技术深度,但全都是解决实际问题的干货,可以当作是问题手册以备后用.本人日常工作偏后端开发,因 ...

  3. vertx的学习总结4之异步数据和事件流

    一.异步数据和事件流 1.为什么流是事件之上的一个有用的抽象? 2.什么是背压,为什么它是异步生产者和消费者的基础? 3.如何从流解析协议数据? 1.  答:因为它能够将连续的事件序列化并按照顺序进行 ...

  4. serdes 常见并口位宽

    serdes主要完成串并转换功能.常见的并口位宽如下: GE/10/25GE/32GE        10/20/40/16/32位 50GE                              ...

  5. js上传多个文件到asp.net core,并实时转存到阿里云oss

    有时候,为了追求便利性,我们可能会让前端直接将文件上传到阿里云OSS,然后将URL提交给ASP.NET.然而,这种做法意味着前端需要拥有OSS的访问密钥,而将密钥存放在前端,无疑增加了被破解的风险.因 ...

  6. Redis存储商品热度

    项目中有一个需求,就是可以根据商品的热度进行排序 起初想着使用string类型来存储如: sku:hotscore:商品的ID 但是这回有个问题,当商品数量多了那k-v岂不是得炸了,维护起来也非常不方 ...

  7. v0.12.0-敏感词/脏词词标签能力进一步增强

    拓展阅读 敏感词工具实现思路 DFA 算法讲解 敏感词库优化流程 java 如何实现开箱即用的敏感词控台服务? 各大平台连敏感词库都没有的吗? v0.10.0-脏词分类标签初步支持 v0.11.0-敏 ...

  8. Kernel Memory 入门系列:生成并获取文档摘要

    Kernel Memory 入门系列:生成并获取文档摘要 前面在RAG和文档预处理的流程中,我们得到一个解决方案,可以让用户直接获取最终的问题答案. 但是实际的业务场景中,仍然存在一些基础的场景,不需 ...

  9. 华企盾DSC可能造成系统蓝屏奔溃常见处理方法

    1.蓝屏先卸载我们DSC客户端检测是否是我们影响的 2.如果是我们影响的查到版本说明是否有处理过 3.是否有一些不常用的杀毒软件卸载试试 4.如果使用一些USB驱动类的先把USB的注册表改一下试试 5 ...

  10. Salesforce LWC学习(四十六) record-picker组件浅谈

    本篇参考: https://developer.salesforce.com/docs/platform/lwc/guide/reference-graphql.html https://develo ...