UVa 10008 What ' s cryptanalysis? (Water ver.)

Source: Internet
Author: User
Tags time limit uppercase letter

10008-what ' s cryptanalysis?

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=949

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

Input

The a single positive decimal integer n for the contains of input. This is the number of lines which follow in the input. The next n lines would 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, then followed by a positive decimal in Teger. The integer indicates how to many the corresponding letter appears in the input text. Upper and lower case letters into the input are to be considered the same. No other characters must to be counted. The output must is sorted in descending count order; That's, the most frequent letter are on the "on" the "on" the "the", and "the", "the", "indicates" least frequent le Tter. IF two letters have the same frequency, then the letter which comes the the the alphabet of the the in the must of the the in the the output. If A letter does isn't appear in the text, then this letter must not 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

Complete code:

/*0.016s*/
  
#include <cstdio>
#include <algorithm>
using namespace std;
  
struct Letter
{
    char ch;
    int num;
    BOOL operator < (const letter a) const
    {return
        num!= a.num? num > A.num:ch < a.ch;
    }
} HASHTABLE[27];
  
Char str[100];
  
int main (void)
{
    int n;
    scanf ("%d\n", &n);///read swap line ~ for
    (int i = 0; i < i++)
        hashtable[i + 1].ch = ' A ' + i;
    for (int i = 0; i < n; i++)
    {
        gets (str);
        for (int j = 0; str[j]; j +)
            if (Str[j] >= ' A ' && str[j] <= ' Z ' | | str[j] >= ' A ' && Str[j] & Lt;= ' z ')
                hashtable[str[j] & 31].num++;
    }
    Sort (HashTable + 1, HashTable +);
    for (int i = 1; I <= i++)
        if (hashtable[i].num)
            printf ("%c%d\n", hashtable[i].ch, hashtable[i].num); 
  return 0;
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.