UVa 10008 What's Cryptanalysis? (water ver.)

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

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

完整代码:

/*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);///读掉换行~
    for (int i = 0; i < 26; 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] <= 'z')
                HashTable[str[j] & 31].num++;
    }
    sort(HashTable + 1, HashTable + 27);
    for (int i = 1; i <= 26; i++)
        if (HashTable[i].num)
            printf("%c %d\n", HashTable[i].ch, HashTable[i].num);
    return 0;
}

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索int
, text
, output
, str
, The
must
cryptanalysis、linear cryptanalysis、视频渲染错误10008、10008、imovie渲染失败10008,以便于您获取更多的相关知识。

时间: 2024-11-17 16:12:12

UVa 10008 What's Cryptanalysis? (water ver.)的相关文章

UVa 10656 Maximum Sum (II) (water ver.)

10656 - Maximum Sum (II) Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1597 In a given a sequence of non-negative integers you will have to find such a

UVa 12640 Largest Sum Game (water ver.)

12640 - Largest Sum Game Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=602&page=show_problem&problem=4388 题目:http://uva.onlinejudge.org/external/126/12640.pdf 主要是读取数据怎么处理. 完整代码: /*0

UVa 10921 Find the Telephone (water ver.)

10921 - Find the Telephone Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1862 In some places is common to remember a phone number associating its digits

UVa 10019 Funny Encryption Method (water ver.)

10019 - Funny Encryption Method Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=960 The Problem History : A student from ITESM Campus Monterrey plays with

UVa 10346 Peter&#039;s Smokes (water ver.)

10346 - Peter's Smokes Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1287 Peter has n cigarettes. He smokes them one by one keeping all the butts. Out o

UVa 11498 Division of Nlogonia (water ver.)

11498 - Division of Nlogonia Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2493 The Problem After centuries of hostilities and skirmishes between the fo

UVa 457 Linear Cellular Automata (water ver.)

457 - Linear Cellular Automata Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=398 A biologist is experimenting with DNA modification of bacterial colonie

UVa 11044 Searching for Nessy (water ver.)

11044 - Searching for Nessy Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=1985 The Loch Ness Monsteris a mysterious and unidentified animal said to inha

UVa 102 Ecological Bin Packing (water ver.)

102 - Ecological Bin Packing Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=38 Background Bin packing, or the placement of objects of certain weights int