What a Simple Research
来源:互联网 发布:淘宝联盟导购和推广位 编辑:程序博客网 时间:2024/06/06 12:03
Problem F. What a Simple Research
Description
Peking University Student Folk MusicBand has a history of more than 90 years. They play Chinese traditional musicby Chinese traditional instruments, such as Pipa, Erhu and Guzheng, etc. DoctorLi is a member of that band, and also a former ACMer. Now he is doing someresearch on Chinese ancient music. Many Chinese ancient music has only five kindsof tones, which can be denoted by 'C','D','E','G', and 'A'. Given a piece of musicscore, Li wants to do some simple statistics.
Input
There are no more than 20 test cases.
In each test case:
The first line contains two integers nand m (2<= n,m <= 20), indicating that a piece of music score isrepresented by an n×m matrix of tones. Only 'C','D','E','G' and 'A' can appear in thematrix.
Then the n×m matrix follows.
The input ends with a line of "00".
Output
For each test case:
For each kind of tone shown in thematrix, calculate the appearing times of it, and print the result in descendingorder according to the appearing times. If more than one kind of tones has thesame appearing times, print them in the lexicographical order.
Sample Input
4 5
AGCDE
AGDDE
DDDDD
EEEEE
2 4
GADC
CDEE
0 0
SampleOutput
D 8 E 7 A 2 G 2 C 1
C 2 D 2 E 2 A 1 G 1
题意:求一个矩阵中各个字母出现的次数。比较简单,模拟求解。
Code:
#include<cstdio>#include<algorithm>using namespace std;struct node{char c;int x;}h[6];bool cmp(node a,node b){return a.x>b.x;}int main(){int n,m;scanf("%d%d",&n,&m);while (n!=0 && m!=0) {char ch[100];for (int i=1;i<=5;i++) h[i].x=0;for (int i=1;i<=n;i++) {scanf("%s",ch);for (int j=0;j<m;j++) {if (ch[j]=='A') h[1].x++;if (ch[j]=='C') h[2].x++;if (ch[j]=='D') h[3].x++;if (ch[j]=='E') h[4].x++;if (ch[j]=='G') h[5].x++;}}h[1].c='A',h[2].c='C',h[3].c='D',h[4].c='E',h[5].c='G';sort(h+1,h+6,cmp);int p=5;for (int i=1;i<=5;i++) {if (h[i].x==0) {p=i-1;break;}}for (int i=1;i<=p-1;i++) printf("%c %d ",h[i].c,h[i].x);printf("%c %d\n",h[p].c,h[p].x);scanf("%d%d",&n,&m);}return 0;}
- What a Simple Research
- What a Simple Research HihoCoder
- hihocoder 1427 What a Simple Research
- Writing a Research Paper
- Writing a Research Essay
- uva10837 A Research Problem
- A Research Problem UVA
- A Research Problem UVA
- Python 3.1 Study notes 1: What a simple function can tell.
- Build a Simple Program Using Boost in(std::cin) : What does it mean?
- A Roadmap to Good Research
- WRITING A SCIENTIFIC RESEARCH ARTICLE
- A - Eddy's research II
- What I Have Learned From My First Scientific Research
- magasin abercrombie france Historical research on what kind of value
- What Is SNMP(Simple Network Management Protocol )
- Research
- Research
- Chapter 1 引言
- 【BZOJ 4238】电压
- 扩展欧几里德算法详解
- 【JAVA】通过HttpURLConnection 上传和下载文件
- Gym
- What a Simple Research
- XCODE中SVN不能提交.A文件的解决方法
- Spring Boot(2)弃坑了
- 课堂练习1:定义一个交通工具(Vehicle)类,其中有: 属性:速度(speed),体积(size) 方法:移动(move()),设置速度(setSpeed(int speed)),设置体积
- 转换函数
- JavaSE_8系列博客——Java语言的特性(六)--泛型(3)--泛型和类型通配符
- oc 函数多个参数调用
- 数字转星期
- 哔哩哔哩动画面试面筋