ACM计数问题

来源:互联网 发布:淘宝店加盟是真的吗 编辑:程序博客网 时间:2024/06/05 20:24

count

TimeLimit:1 Second MemoryLimit:32 Megabyte

Totalsubmit:699 Accepted: 158

Description

Given a number of strings, can you find how many times a string appear in the input?

Input

The input contains multiple test cases. Each case begins with a integer N(the number of strings you will get, N<=100000), followed by N lines, each consists of a string.

Output

For each test case, print "Case K:" where K is the Kth case. K begins with 1. Then print the times(T) a string appears and the number(M) of strings that appear T times. Don't print T or M where M<=0. The output is ordered by T. The length of each strings won't longer than 20.

Sample Input


5
BBA
BBA
BEA
DEC
CCF

Sample Output


Case 1:
1 3
2 1

 

 

 

C预言实现如下;

 #include<stdio.h>#include<string.h>#include<stdlib.h> typedef struct ee{       char str[21];}node;node a[100001];    void show(int sum[],int m){       int i;       for( i = 1; i <= m; i++)       {              if( sum[i] != 0)                     printf("%d %d\n",i,sum[i]);       }} int cmp( const void *n1, const void *n2){       node *a = (node*) n1;       node *b = (node*) n2;       char *str1 = a->str;       char *str2 = b->str;       return strcmp(str1,str2);} int main(){        int n,num,k;       char s[21];       k = 1;       int sum[100001];       while( scanf("%d",&n) != EOF)       {              if( n <= 0 || n > 100000)                     break;              memset(sum,0,100001);              num = 1;              int i,temp;              for( i = 0; i < n; i++ )              {                     scanf("%s",a[i].str);              }              qsort(a,n,sizeof(a[0]),cmp);               strcpy(s,a[0].str);              temp = 1;              for( i = 1; i < n; i++ )              {                     if( strcmp(s,a[i].str) == 0)                            temp++;                     else                     {                            strcpy(s,a[i].str);                            sum[temp]++;                            temp = 1;                     }              }              sum[temp]++;              printf("Case %d:\n",k++);              show(sum,n);       }       return 0;} 


 

原创粉丝点击