我是靠谱客的博主 可靠小笼包,最近开发中收集的这篇文章主要介绍ACM计数问题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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 %dn",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;
}


 

最后

以上就是可靠小笼包为你收集整理的ACM计数问题的全部内容,希望文章能够帮你解决ACM计数问题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(80)

评论列表共有 0 条评论

立即
投稿
返回
顶部