10008 - What's Cryptanalysis?

 What's Cryptanalysis? 

Cryptanalysis is the process of breaking someone else's cryptographicwriting. This sometimes involves some kind of statistical analysis ofa passage of (encrypted) text. Your task is to write a programwhich 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 includingwhitespace). This is the text which must be analyzed.

Output 

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

Sample Input 

3
This is a test.
Count me 1 2 3 4 5.
Wow!!!!  Is this question easy?

Sample Output 

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<iostream>
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
int main()
{
	int n,a[150]={0};
	char ch;
	cin>>n;
	getchar();
	for(int i=0;i<n;)
	{
		if((ch=getchar())!='\n')
		{
			if(isalpha(ch))
			{
				ch=toupper(ch);
				a[ch]++;
			}
		}
		else 
			i++;
	}
	int b[150]={0};
	for(int i=0;i<150;i++)
		b[i]=a[i];
	sort(b,b+150);
	for(int i=149;i>0;i--)
		if(b[i])
		{
			for(int j=0;j<150;j++)
				if(a[j]==b[i])
				{putchar(j);a[j]=0;break;}
				cout<<" "<<b[i]<<endl;
		}
		return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值