Nickname
来源:互联网 发布:淘宝大尺度买家秀18p 编辑:程序博客网 时间:2024/04/29 10:12
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
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
- Nickname
- 1825. Nickname
- sicily1825. Nickname
- Nickname of US States
- NickName做成手册
- 创建nickname 整理版
- Sicily 1825 Nickname
- DB2 如何创建nickname
- DB2 如何创建nickname
- Sicily 1825. Nickname
- db2 创建联邦数据库 /nickname
- 微信获取nickname、openid
- db2 USER MAPPING, CREATE SERVER机NICKNAME
- db2 使用nickname 访问其它库的表
- DB2 创建和使用nickname 报错 SQL1101N
- [android研究联系人之二]联系人Email/Nickname数据操作
- DB2 创建和使用nickname 报错 SQL1101N
- db2 使用nickname 访问其它库的表
- 大型网站系统架构
- loadrunner 利用sitescope监测监控mysql性能(添加mysql计数器)
- 关于java判断sql是否执行成功
- 显示父div范围
- Bootstrap3学习笔记---2
- Nickname
- 获取手机所有安装的app(转的)
- Uboot 详解
- linux脚本编程---vim的使用(1)
- com.atomikos.icatch.SysException: Error in init(): Log already in use
- hdu 4687 带花树求一般图最大匹配(模板)
- 二分图匹配(KM算法)n^4
- 数字签名与数字证书
- 关于cocos2dx坐标及几个重要函数说明