STL练习——registration system

本文介绍了一个使用C++实现的简单用户名注册系统。该系统能够处理重复用户名,并为已存在的用户名生成带数字后缀的新版本。代码展示了如何读取输入、比较字符串以及输出响应。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
#include<cstdio>
#include<iostream>
#include<cstring>

using namespace std;

int main(){
	int nCase,n;
	char str[105][1005],a[105];
	scanf("%d",&nCase);
	n=nCase;
	for(int i=0;i<n;i++)
		a[i]='0';
	while(nCase--){
		int j=1;
		scanf("%s",str[n-nCase]);
		for(int i=0;i<n-nCase;i++)
			if(strcmp(str[i],str[n-nCase])==0){
				a[i]++;
				int d=strlen(str[n-nCase]);
				str[n-nCase][d]=a[i];
				printf("%s%c\n",str[i],a[i]);
				j=0;
				break;
			}
			if(j){
				printf("OK\n");
			}
	}
	return 0;

	}
        

输入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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值