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;}
- ACM计数问题
- acm-polya计数公式
- ACM 砖块计数
- 计数问题
- 计数问题
- 计数问题
- 计数问题
- 计数问题
- 计数问题
- 计数问题
- 计数问题
- 计数问题
- ACM-计数排序小例子
- ACM 158. [USACO Oct07] 奶牛饮水(计数)
- ACM组队安排 (DFS+计数原理)
- 序关系计数问题
- 多重幂计数问题
- 多重幂计数问题
- Android学习——org.json.JSONException: End of input at character 0 of
- 第八周项目2——分段函数求值2
- 手机号码测凶吉,学习阶段,感觉蛮好玩,我是用NetBeansIDE做的
- 月薪过万应届生的10个忠告,抽点时间看看,真心受用!!
- qsort函数应用大全(转)
- ACM计数问题
- 第八周项目2扩展——分段函数求值3
- 如果让我重做一次研究生--王泛森院士
- LINUX OS ANT一键安装制作 JAVA WEB + TOMCAT7.0 RPM 安装包
- EXTJS+STRUTS图片上传
- mt.exe : general error c101008d: Failed to write the updated manifest to the resource of file
- XE5 JSON与Delphi Object的互换
- reading books not technology
- 下载源代码时候的一个错误解决办法