UVA 10008 - What's Cryptanalysis?
来源:互联网 发布:全日制本科助学班 知乎 编辑:程序博客网 时间:2024/05/24 05:55
What's Cryptanalysis?
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
3This is a test.Count me 1 2 3 4 5.Wow!!!! Is this question easy?
Sample Output
S 7T 6I 5E 4O 3A 2H 2N 2U 2W 2C 1M 1Q 1Y 1
水题
但是写
if(s[j] >= 'a' && s[j] <= 'z') { s[j] = s[j] - 'a' + 'A'; } if(s[j] >= 'A' && s[j] <= 'Z') { a[s[j] - 'A'].num++; }就能AC
写
a[toupper(s[j]) - 'A'].num++;
就RE!!!
康神一眼就看出我的字符串里不一定都是字母,如果是其他字符,toupper一下就必然RE了
#include<cstdio>#include<iostream>#include<string>#include<vector>#include<map>#include<set>#include<algorithm>#include<cmath>#include <cstring>#include <queue>using namespace std;#define eps 1e-20#define MAXN 100000 + 10#define outstars cout << "*********" << endl;char s[MAXN];struct AA{ int id; int num;} a[30];bool cmp(const AA a , const AA b){ if(a.num == b.num)return a.id < b.id; return a.num > b.num;}int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i = 0 ; i < 26 ; i++) { a[i].num = 0; a[i].id = i; } getchar(); for(int i = 0 ; i < n ; i++) { gets(s); for(int j = 0 ; j < strlen(s) ; j++) { if(s[j] >= 'a' && s[j] <= 'z') { s[j] = s[j] - 'a' + 'A'; } if(s[j] >= 'A' && s[j] <= 'Z') { a[s[j] - 'A'].num++; } } } sort(a , a + 26 , cmp); for(int i = 0 ; i < 26 ; i++) { if(a[i].num) { printf("%c %d\n",a[i].id + 'A' , a[i].num); } } } return 0;}/**/
- uva 10008 What's Cryptanalysis?
- UVA 10008 - What's Cryptanalysis?
- UVa 10008 - What's Cryptanalysis?
- UVA 10008 What's Cryptanalysis?
- uva 10008 What's Cryptanalysis?
- UVa OJ 10008-What's Cryptanalysis?
- UVa 10008 What's Cryptanalysis? (water ver.)
- 10008 - What's Cryptanalysis?
- What's Cryptanalysis?(map)
- E -What's Cryptanalysis?
- UVA, 10008 What's Cryptanalysis?(先按次数从大到小排列,后按照字典中的字母顺序)
- UVA 10008 whats cryptanalysis 水题
- (字符串的模式匹配4.7.8)UVA 10008 What's Cryptanalysis?(统计文本中某一个字符的出现的次数,需要从小到大排序&&同次数的按字段序排序)
- UVa 499 - What's The Frequency, Kenneth?
- what's
- Cryptanalysis of Microsoft's PPTP Authentication Extensions (MS-CHAPv2)
- what's wap 2.0
- what's love?
- poj 1023
- HDU 1064 Financial Management
- 11039 - Building designing
- WordPress无插件调用最新、热门、随机文章
- 互联网史话---十亿美金在云上
- UVA 10008 - What's Cryptanalysis?
- 华为云服务(HWClouds)之对象存储服务试用
- 报表导出Excel 二 :将业务报表数据写入特定Excel模板
- 华为Y300-0000手机解锁Bootloader步骤
- 一种移动GIS离线数据采集的方法
- NYOJ 22素数求和
- delete 分批提交删除数据表记录
- 【C开发】无限循环 while(1) 和 for(; ;)
- 关于IOS的Autolayout特性的理解以及使用