字符统计3 SDUT 2104
来源:互联网 发布:js 调用微信打开链接 编辑:程序博客网 时间:2024/04/29 08:14
题目描述
给定一个字符串(假设字符串中只包含英文大小写字母),排序输出出现次数最多的三个字符,如果有两个字符出现次数相等,输出字母序列靠前的(提示这里指的是字母在ASCII码表中的顺序),如果不足三个,把现有的输出。例如:对于字符串mddfreee,输出:(e,3)(d,2)(f,1)。输入aab,输出 (a,2)(b1),注意后台测试数据的字符串可能会非常长。
输入
第一行为一个整数N,代表有几组输入。接下来N行分别代表待统计的字符串。
输出
对于给定的每次输入,输出结果。每个实例占一行格式如下。
示例输入
4abcdeassssddfffrtbaabbbaaaaaaB
示例输出
(a,1)(b,1)(c,1)(s,4)(f,3)(d,2) (a,7)(b,4)(B,1)(a,1)#include<stdio.h>#include<string.h>struct node{ int a; int b;}str[100100],t;int main(){ int n; char q[100100],c; scanf("%d",&n); getchar(); while(n--) { gets(q); int k=strlen(q); for(int i=0; i<k-1; i++) { for(int j=0; j<k-i-1; j++) { if(q[j]>q[j+1]) { c=q[j]; q[j]=q[j+1]; q[j+1]=c; } } } int cout=1,l=0; for(int i=0; i<k; i++) { if(q[i]==q[i+1]) { cout++; } else { str[l].a=q[i]; str[l].b=cout; l++; cout=1; } } for(int i=0; i<l-1; i++) { for(int j=0; j<l-i-1; j++) { if(str[j].b<str[j+1].b) { t=str[j]; str[j]=str[j+1]; str[j+1]=t; } } } if(l>2) { for(int i=0; i<=2; i++) { printf("(%c,%d)",str[i].a,str[i].b); } } else { for(int i=0; i<l; i++) { printf("(%c,%d)",str[i].a,str[i].b); } } printf("\n"); } return 0;}
0 0
- 字符统计3 SDUT 2104
- sdut 字符统计2
- sdut acm 字符统计2
- 字符统计1 (sdut oj)
- 字符统计2 (sdut oj)
- 字符统计2 sdut 1525
- SDUT-1219 字符统计1
- SDUT-1525 字符统计2
- [1525]字符统计2 (哈希)SDUT
- SDUT ACM 实验九 字符统计1
- 【2674】3-5 学生成绩统计 SDUT
- sdut 3-5 学生成绩统计
- SDUT-2674 3-5 学生成绩统计
- 字符统计3
- 字符统计3
- 统计元音 (sdut oj)
- 选票统计 (sdut oj)
- SDUT-1250 统计元音
- 下载电驴屏蔽资源办法
- Continuously Integrate
- 架构师速成8.3-架构师必须要了解的规则
- IT忍者神龟之Microsoft Office Enterprise 2007 简体版 企业版 序列号
- Eclipse中10个最有用的快捷键组合
- 字符统计3 SDUT 2104
- 架构师速成8.3-可用性
- Avoid Scheduling Failures
- 復之之理
- 如何提高nodejs程序的稳定性,健壮性
- Qt中使用ActiveX(一)
- AForge类库调用摄像头
- Algorithms—143.Reorder List
- IOS开发-文件管理(二)