Registration system

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述

  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.

 
输入
  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 1000 characters, which are all lowercase Latin letters.
输出
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.
样例输入
  4
  abacaba
  acaba
  abacaba
  acab
样例输出
  OK
  OK
  abacaba1
  OK
/**
分析:该题是,判断一个新输入字符串是否属于原先字符串序列
①"不属于" : 打印"OK"表示插入成功
②"属于" : 判断是第几次出现该串(序列号) --> 并打印:"该串" + 序列号
方法:map <string, int>
模板:
map <string, int> my_map;
pair <map <string, int> :: iterator, bool> pr; pr = my_map.insert (map <string, int> (str, 0));
if (!pr.second)
{
++ my_map [str];
cout <<str <<my_map [str] <<endl;
}
else
{
cout <<"OK" <<endl;
}
**/

C/C++代码实现:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <stack>
#include <queue>
#include <map> using namespace std; int N; string str; int main () {
~scanf ("%d", &N);
map <string, int> my_map;
pair <map <string, int> :: iterator, bool> pr; while (N --) {
cin >>str;
pr = my_map.insert (pair <string, int> (str, ));
if (!pr.second) { // 插入失败
my_map [str] ++;
cout <<str <<my_map [str] <<endl;
} else {
printf ("OK\n");
}
}
return ;
}

nyoj 991 Registration system (map)的更多相关文章

  1. nyoj 911 Registration system(map)

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

  2. nyoj Registration system

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

  3. (用了map) Registration system

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

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

  5. ACM Registration system

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

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

  7. CodeForces-4C Registration system

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

  8. codeforces Registration system

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

  9. System.map文件【转】

    转自:http://blog.csdn.net/david104/article/details/7194185 当运行GNU链接器gld(ld)时若使用了"-M"选项,或者使用n ...

随机推荐

  1. 部署在本服务器上,Jenkins无法启动Tomcat

    今天在部署Jenkins的过程中,有一个需要部署在本服务器上的Web服务,而且Jenkins给我的反馈也是成功的部署了,且Tomcat启动起来了,但是实际打开项目发现其实并没有启动起来 在查看日志的时 ...

  2. 微信小程序之媒体查询@media

    微信小程序支持媒体查询,代码如下: @media screen and (min-width: 700px) { .container { padding: 30rpx; } } @media scr ...

  3. Java中package与import

    使用实例: package 一般来说,package语句必须作为源文件的第一条非注释性语句.一个java源文件只能指定一个包,即只能包含一条package语句,该源文件中可以定义多个类,则这些类将全部 ...

  4. 热烈祝贺达孚电子(NDF)网站上线

    尊敬的客户: 您们好! 为适应公司发展的需要,树立公司的良好形象,满足大家更多的了解电容器系列产品及公司的服务,经过1个多月的筹备,在2019年10月21日公司网站正式上线啦,这标志着NDF(达孚电子 ...

  5. Java IO编程——File文件操作类

    在Java语言里面提供有对于文件操作系统操作的支持,而这个支持就在java.io.File类中进行了定义,也就是说在整个java.io包里面,File类是唯一 一个与文件本身操作(创建.删除.重命名等 ...

  6. Redis(十一)缓存设计

    一.缓存的收益和成本 左侧为客户端直接调用存储层的架构,右侧为比较典型的缓存层+存储层架构, 缓存加入后带来的收益如下: 加速读写:因为缓存通常都是全内存的(例如Redis.Memcache),而存储 ...

  7. 品优购(IDEA版)-第一天

    # 品优购(IDEA版)-第一天 品优购IDEA版应该是2019年的新项目.目前只有视频.资料其他都还是旧的. ## 1.学习目标 1:了解电商行业特点以及理解电商的模式 2:了解整体品优购的架构特点 ...

  8. 23 个重难点突破,带你吃透 Service 知识点「长达 1W+ 字」

    前言 学 Android 有一段时间了,想必不少人也和我一样,平时经常东学西凑,感觉知识点有些凌乱难成体系.所以趁着这几天忙里偷闲,把学的东西归纳下,捋捋思路. 这篇文章主要针对 Service 相关 ...

  9. CSAPP:代码优化【矩阵读写】

    转载请注明出处:https://www.cnblogs.com/ustca/p/11790314.html 写程序最主要的目标就是使它在所有可能的情况下都正确工作,另一方面,在很多情况下,让程序运行得 ...

  10. python基础-流程控制(if,while,for)

    今日内容总结 --流程控制(if,while,for) if:用来判断事物的对错.真假.是否执行.根据不同的情况判断,条件满足执行某条件下的语句 语法结构(3种) # 第一种,只有if结构.条件表达式 ...