UVa10008:What's Cryptanalysis?

题目:将输入中出现的字母 数量从多到少, 从上到下排列, 若字母数量相同, 按A—>Z的顺序排序(小写转换为大写并输出) 

Input

輸入的第1列有一個正整數n,代表以下有多少列需要作分析的密文。

接下來的n列,每列含有0或多個字元(可能包含空白字元)

Output

每列包含一個大寫字元(A~Z)和一個正整數。這個正整數代表該字元在輸入中出現的次數。輸入中大小寫(例如:A及a)視為相同的字元。輸出時請按照字元出現的次數由大到小排列,如果有2個以上的字元出現次數相同的話,則按照字元的大小(例如:A在H之前)由小到大排列。

請注意:如果某一字元未出現在輸入中,那他也不應出現在輸出中。

What's Cryptanalysis?

Time Limit: 3 sec

Description

Cryptanalysis is the process of breaking someone else's cryptographic writing. This sometimes involves some kind of statistical analysis of a passage of (encrypted) text. Your task is to write a program which performs a simple analysis of a given text.

Input

The first line of input contains a single positive decimal integer n. This is the number of lines which follow in the input. The next n lines will contain zero or more characters (possibly including whitespace). This is the text which must be analyzed.

Output

Each line of output contains a single uppercase letter, followed by a single space, then followed by a positive decimal integer. The integer indicates how many times the corresponding letter appears in the input text. Upper and lower case letters in the input are to be considered the same. No other characters must be counted. The output must be sorted in descending count order; that is, the most frequent letter is on the first output line, and the last line of output indicates the least frequent letter. If two letters have the same frequency, then the letter which comes first in the alphabet must appear first in the output. If a letter does not appear in the text, then that letter must not appear in the output。


Sample Input

Sample Output

3

This is a test.

Count me 1 2 3 4 5.

Wow!!!!  Is this question easy?

S 7

T 6

I 5

E 4

O 3

A 2

H 2

N 2

U 2

W 2

C 1

M 1

Q 1

Y 1

 

#include <stdio.h>
#include <string.h>

int main()
{
	int test, i, j;
	int az[26]={0};
	
	scanf("%d\n",&test);
	while(test--)
	{
		char str[101]={0};
		gets(str);
		for(i=0; i<strlen(str); i++)	//将所有小写字母转换为大写
			if(str[i]>='a' && str[i]<='z') str[i]+='A'-'a'; 
		
		for(i=0; i<strlen(str); i++)	//统计每个字母的个数
			if(str[i]>='A' && str[i]<='Z') az[str[i]-'A']++;
	}
		
	int max=0;
	for(i=0; i<26; i++)	
		if(az[i]>max) max=az[i]; //计算出字母数量最大值
	
	for(j=max; j>0; j--)	 //从最大值开始,从大到小找,从上到下排列
		for(i=0; i<26; i++)	//从A到Z依次排序
			if(az[i]==j) 
				printf("%c %d\n",'A'+i,j);
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值