nyoj Registration system
Registration system
- 描述
-
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
#include <iostream>
#include <map>
using namespace std;int main()
{
int n;
map<string,int> m;
cin>>n;
while(n--)
{
string s;
cin>>s;if(m[s])
cout<<s<<m[s]<<endl;
else
cout<<"OK"<<endl;
m[s]++;
}
return 0;
}map:数据的插入
在构造map容器后,我们就可以往里面插入数据了。这里讲三种插入数据的方法:
第一种:用insert函数插入pair数据
map<int, string> mapStudent;
mapStudent.insert(pair<int, string>(1,“student_one”));第二种:用insert函数插入value_type数据
map<int, string> mapStudent;
mapStudent.insert(map<int, string>::value_type (1,"student_one"));mapStudent.insert(make_pair(1, "student_one"));
第三种:用数组方式插入数据map<int, string> mapStudent;
mapStudent[1] = “student_one”;
mapStudent[2] = “student_two”;/*如果是
#include <map>
map<string, int> mapStudent;string s;
插入就用m[s]++;*/以上三种用法,虽然都可以实现数据的插入,但是它们是有区别的,当然了第一种和第二种在效果上是完成一样的,用insert函数插入数据,在数据的插入上涉及到集合的唯一性这个概念,即当map中有这个关键字时,insert操作是不能再插入这个数据的,但是用数组方式就不同了,它可以覆盖以前该关键字对应的值,即:如果当前存在该关键字,则覆盖改关键字的值,否则,以改关键字新建一个key—value;
nyoj Registration system的更多相关文章
- nyoj 911 Registration system(map)
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- nyoj 991 Registration system (map)
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- ACM Registration system
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- 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 ...
- c题 Registration system
Description A new e-mail service "Berlandesk" is going to be opened in Berland in the near ...
- CodeForces-4C Registration system
// Registration system.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include <iostream> # ...
- (用了map) Registration system
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93241#problem/C (654123) http://codeforces.com ...
- codeforces Registration system
Registration system A new e-mail service "Berlandesk" is going to be opened in Berland in ...
- 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 ...
随机推荐
- php fpm深度解析
摘自:https://www.cnblogs.com/wanghetao/p/3934350.html 当我们在谈到cgi的时候,我们在讨论什么 最早的Web服务器简单地响应浏览器发来的HTTP请求, ...
- ubuntu下没有Language Support
sudo apt-get installlanguage-selector-gnome
- 44. Wildcard Matching *HARD*
'?' Matches any single character. '*' Matches any sequence of characters (including the empty sequen ...
- 微信小程序--登录流程梳理
前言 微信小程序凡是需要记录用户信息都需要登录,但是也有几种不同的登录方式,但是在小程序部分的登录流程是一样的.之前就朦朦胧胧地用之前项目的逻辑改改直接用了,这个新项目要用就又结合官方文档重新梳理了下 ...
- 从零开始学习Vue(二)
思维方式的变化 WebForm时代, Aspx.cs 取得数据,绑定到前台的Repeater之类的控件.重新渲染整个HTML页面.就是整个页面不断的刷新;后来微软打了个补丁,推出了AJAX控件,比如U ...
- 如何解决请求URL长度超过配置的maxurlLength值问题
当我们批量请求的数据太多时,会出现请求的url长度超过配置maxurllength值的问题(比如一次性操作1000条数据) 1.问题描述: 我在进行批量选择单据进行发送时,出现这个问题(批量500条) ...
- Quartz定时任务和IIS程序池闲置超时时间冲突解决方案
一.问题描述 Bs项目中用Quartz功能执行一个定时任务(每隔5分钟执行一个Job),正常情况,Quartz定时任务会5分钟执行一次,但IIS程序池闲置 超时默认为20分钟,造成的结果是:定时任务只 ...
- 什么是 dynaTrace Ajax
随着 jQuery.Dojo.YUI 等框架的兴起让构建 Web2.0 应用更加容易,但随之带来的定位等应用问题也越来越难,尤其是与性能相关的.dynaTrace Ajax Edition 是一个强大 ...
- python爬虫常见面试题(一)
前言 之所以在这里写下python爬虫常见面试题及解答,一是用作笔记,方便日后回忆:二是给自己一个和大家交流的机会,互相学习.进步,希望不正之处大家能给予指正:三是我也是互联网寒潮下岗的那批人之一,为 ...
- ios数据持久化(转)
文件系统 归档和序列化 数据库 1.文件系统 不管是Mac OS X 还是iOS的文件系统都是建立在UNIX文件系统基础之上的. 1.1 沙盒模型 在iOS中,一个App的读写权限只局限于自己的沙盒目 ...