C. Registration system

题目链接:http://codeforces.com/problemset/problem/4/C

4C. Registration system

time limit per test5 seconds
memory limit per test64 megabytes
inputstandard input
outputstandard output

题目描述
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),前面有相同的则对应加上数字(name1,name2,name3…),并输出。
反之,则注册为name,并输出OK

思路:使用map函数,读入的数据都是对应关系,且每个数据只能出现一次,第二次出现称为该数据的对应值。以此类推。

代码

#include<iostream>
#include<map>
#include<string>
using namespace std; 
int main()
{
	map<string,int> m;
	string s;
	int n;
	cin>>n;
	while(n--)
	{
		cin>>s;
		m[s]++;
		if(m[s]>1)
		{
			cout<<s<<m[s]-1<<endl;
		}
		else
		{
			cout<<"OK"<<endl;
		}
	}
	return 0;}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
As a stakeholder, I want to develop an online food ordering and delivery system that allows users to browse menus, place orders, and track deliveries. The system should have the following features and functions: Features: - User registration and login - Menu browsing - Order placement and modification - Payment processing - Delivery tracking - Rating and feedback system - Restaurant management interface Functions: - Users can browse menus from multiple restaurants - Users can add items to their cart, modify their order, and place the order - Users can pay for their order through the system - Users can track their delivery status in real-time and receive notifications - Users can rate their experience and provide feedback - Restaurants can manage their menu, orders, and delivery status through an interface Inputs: - User login information - Restaurant menu and order information - Payment information Outputs: - Confirmation of order placement - Delivery status updates - Receipt of payment Scenarios: 1. A user logs in to the system and browses menus from different restaurants. They add items to their cart, modify their order, and place the order. They pay using the system and receive confirmation of their order placement. They then track their delivery status and receive updates until the food is delivered. 2. A restaurant logs in to the system and updates their menu. They receive an order from a user, confirm the order, and update the delivery status. They receive feedback from the user and use it to improve their service. System Interactions: - The system interacts with payment gateways to process payments - The system interacts with delivery services to provide real-time tracking - The system interacts with restaurant management interfaces to update menus, orders, and delivery status Data Model: ```mermaid graph TD A[User] -->|places order|B(Order) B -->|contains|C(Item) D[Restaurant] -->|offers menu|C B -->|has payment information|E(Payment) B -->|has delivery information|F(Delivery) ``` Process Model: ```mermaid graph TD A[User] -->|places order|B(Order) B -->|selects items and quantity|C(Add Items) B -->|modifies order|D(Modify Order) B -->|confirm order|E(Confirm Order) E -->|process payment|F(Payment) F -->|initiate delivery|G(Delivery) G -->|update delivery status|H(Delivery Status) ``` Behavior Model: ```mermaid stateDiagram [*] --> Login Login --> Browse: User logs in Browse --> Add: User selects items Add --> Modify: User adds item to cart Modify --> Confirm: User modifies order Confirm --> Payment: User confirms order Payment --> Delivery: Payment is processed Delivery --> Feedback: Delivery status is updated Feedback --> Browse: User provides feedback ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稚皓君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值