Nickname

Problem Description
ZSUQ Messenger is similar with Tencent QQ. Each user will make a nickname for itself. Different users can have identical nickname. Some common ones, such as "Tom","Marry","Kate", are frequently used. In a recent survey, the ZSUQ Company was astonished to find that there are no more than 5000 distinct nicknames that are being used.
Being a member of the ZSUQ Company, you are asked to make a report, telling the number of users for each nick name. A complete list of all users' nicknames is provided to you. Please note that nicknames are case insensitive.
Input
The first line of the file contains an integer indicating the number of test cases.
In each test case, there is an integer N in the first line (0<N<100000). The following N lines describe N users' nicknames. Each name consists of no more than 100 characters. There is a bland line between two cases.
Output
For each case, give out a list of the distinct nickname, one per line, followed by a bland space and the number of users who has this nickname. The names are in alphabetic order. There is no bland space at the beginning or the end of each line. Nicknames should be presented in lowercase letter. There is a bland line between two cases.
Sample Input
1
4
carp
inkfish
peipei
carp
Sample Output
carp 2
inkfish 1

peipei 1

//对快速排序算法的认识太过局限,快速排序不仅仅可以用于整数型,还可以用于其它数据类型

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int n,t,cnt;
char nd[100005][104],ans[100005][104];
int num[100005];
void quickSort(int left,int right)
{  
	int i=left; 
	int j=right;
	char tmp[104];
	strcpy(tmp,nd[left]);
	if(left>=right)
		return;
	while(i!=j)
	{
		while(i<j&&strcmp(nd[j],tmp)>0)
			j--;
		if(j>i)
			strcpy(nd[i++],nd[j]);
		while(i<j&&strcmp(nd[i],tmp)<0)
			i++;
		if(i<j)
			strcpy(nd[j--],nd[i]);
	}
	strcpy(nd[i],tmp);
	quickSort(left,i-1);
	quickSort(i+1,right);
}
int main()
{
	//freopen("b.txt","r",stdin);
	scanf("%d",&t);
	char s[104];
	while(t--)
	{
		scanf("%d",&n);
		int i,j,len;
		cnt=0;
		for(i=0;i<n;i++)
		{
			scanf("%s",s);
			len=strlen(s);
			for(j=0;j<len;j++)
				if(s[j]>='A'&&s[j]<='Z')
					s[j]=s[j]-'A'+'a';
				strcpy(nd[i],s);
		}
		quickSort(0,n-1);
		cnt=0;
		num[cnt]=1;
		strcpy(ans[0],nd[0]);
		for(i=1;i<n;i++)
		{
			//printf("%s\n",nd[i]);
			if(strcmp(ans[cnt],nd[i])==0)
				num[cnt]++;
			else 
			{
				++cnt;
				strcpy(ans[cnt],nd[i]);
				num[cnt]=1;
			}
		}
		for(i=0;i<=cnt;i++)
			printf("%s %d\n",ans[i],num[i]);


		printf("\n");
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值