2021-7-20 Registration system
难度 1300
题目 CodeForces:
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 32 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.
Keyword
site administration 网站管理
implement 执行,实现,实施
prototype 原型
database 数据库
prompt 提示
题目解析
本题大意是有n个用户进行注册,先注册的使用的名字会被记录进数据库中,视为成功注册,后注册同样名字的用户,会以原先名字后面增加数字以后被记录进数据库中,同样也视为成功注册。
本题思路很简单,由于注册的用户只会用小写字母注册,也就意味着事实上重复用户无需记录新名字,只需要记录有多少个重复用户即可
这里我们利用map来存每个名字出现的次数,如果没有出现过,我们就输出"OK"并将这个名字放入数据库,并将这个名字对应的value记为0,如果出现过,我们就输出原先的名字加上该名字对应的value+1,然后将value这个值加上1.
解析完毕,以下为参考代码
1 #include<iostream> 2 #include<map> 3 #include<string> 4 using namespace std; 5 int main() 6 { 7 int n; cin >> n; 8 map<string,int>system; 9 for (int i = 0; i < n; i++) 10 { 11 string m;cin >> m; 12 if (system.find(m) != system.end()) 13 { 14 system[m]++; 15 cout << m << system[m] << "\n"; 16 } 17 else 18 { 19 cout << "OK\n"; 20 system[m] = 0; 21 } 22 } 23 return 0; 24 }
原文地址:https://www.cnblogs.com/lovetianyi/p/15037068.html
- Android一些关于分辨率和布局的设置
- log4net 中错误 System.Web.HttpException (0x80004005): 文件不存在
- Contact Manager Web API 示例[2] Web API Routing
- Python内置函数
- NET实现微信公共平台上传下载多媒体文件
- css3基础知识——回顾
- Contact Manager Web API 示例[3] 分页和查询(Paging and Querying)
- @font-face css3自定义个性化字体
- 你不知道的javaScript笔记(7)
- Contact Manager Web API 示例[4] 异常处理(Exception Handling)
- 你不知道的javaScript笔记(6)
- 创建支持多种屏幕尺寸的Android应用
- 封装多线程处理大量数据操作
- 你不知道的javaScript笔记(5)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 精讲响应式WebClient第6篇-请求失败自动重试机制
- 算法篇:位运算基本操作
- Vue 项目中各种痛点问题及方案
- 算法篇:位运算进阶(二)
- 算法篇:摩尔投票法的使用
- 理解ECMAScript规范(2)
- 算法篇:数的转换
- React 开发要知道的 34 个技巧
- 算法篇:求1的个数
- 新特性解读 | MySQL 8.0 语句摘要功能介绍
- 10个不那么知名但很实用的Web API
- 技术分享 | 一文了解高并发限流算法
- prometheus-operator 监控 k8s 外部集群
- Kubernetes 通过statefulset部署redis cluster集群
- 猿实战13——实现你没听说过的前台类目