What a Simple Research

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JackflyDC

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值