sicily 1825. Nickname
2013-02-04 07:58
351 查看
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 < 100,000). 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 after each case.
水题,转小写预处理,快排,新开字符串数组去重,开一个数组计数,就行了
run time 0.62sec
View Code
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 < 100,000). 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 after each case.
水题,转小写预处理,快排,新开字符串数组去重,开一个数组计数,就行了
run time 0.62sec
View Code
#include<stdio.h> #include<string.h> char nn[100000][101]; char fltrd[100000][101]; int count[100000]; void quicksort( int l, int r ); void lower( char str[] ); int main() { int t, n, i, j; scanf("%d", &t); while(t--) { scanf("%d", &n); for ( i = 0; i < n; i++ ) { scanf("%s", nn[i]); lower( nn[i] ); } quicksort( 0, n-1 ); strcpy( fltrd[0], nn[0] ); j = 0; for( i = 0; i < n; i++ ) count[i] = 1; for ( i = 1; i < n; i++ ) { if( strcmp(fltrd[j],nn[i]) != 0 ) strcpy( fltrd[++j], nn[i] ); else count[j]++; } for ( i = 0; i <= j; i++ ) printf("%s %d\n", fltrd[i], count[i] ); printf("\n"); } return 0; } void quicksort( int l, int r ) { int i = l, j = r; char x[101]; if ( l >= r ) return; strcpy( x, nn[i] ); while ( j > i ) { while( j > i && strcmp(nn[j], x) == 1 ) j--; if( j > i ) strcpy( nn[i++], nn[j] ); while( j > i && strcmp(nn[i], x) == -1 ) i++; if( j > i ) strcpy( nn[j--], nn[i] ); } strcpy( nn[i], x ); quicksort( l, i-1 ); quicksort( i+1, r ); } void lower( char str[] ) { int i; for ( i = 0; str[i] != '\0'; i++ ) if ( str[i] >= 'A' && str[i] <= 'Z') str[i] = str[i] - 'A' + 'a'; }
相关文章推荐
- sicily1825. Nickname
- Sicily 1793. Numbers
- Sicily 3836. 计算组合数
- Sicily 1047 Super Snooker
- sicily1142(深搜加剪枝)
- <OJ_Sicily>Hanoi_Tower_Sequence
- Sicily|1721. Gray code[Special judge]
- Sicily1566——4SUM
- <Sicily>Fibonacci 2
- <OJ_Sicily>Pythagorean Proposition
- sicily Catch the thief
- sicily_homeworkNotes
- Sicily: 连通性问题(算法逐层优化)
- Sicily Message Flood
- Sicily: 1021.Couples
- 第六周:( Sicily1090) Highways(c++)
- Sicily 1211. 商人的宣传
- sicily上前5题
- 【Sicily】1000. 函数求值
- Sicily 1259. Sum of Consecutive Primes |