Problem Description
The relative frequency of characters in natural language texts is very important for cryptography. However, the statistics vary for different languages. Here are the top 9 characters sorted by their relative frequencies for several common languages:

English: ETAOINSHR
German: ENIRSATUD
French: EAISTNRUL
Spanish: EAOSNRILD
Italian: EAIONLRTS
Finnish: AITNESLOK

Just as important as the relative frequencies of single characters are those of pairs of characters, so called digrams. Given several text samples, calculate the digrams with the top relative frequencies.

Input
 
The input contains several test cases. Each starts with a number n on a separate line, denoting the number of lines of the test case. The input is terminated by n=0. Otherwise, 1<=n<=64, and there follow n lines, each with a maximal length of 80 characters. The concatenation of these n lines, where the end-of-line characters are omitted, gives the text sample you have to examine. The text sample will contain printable ASCII characters only.
 
Output
For each test case generate 5 lines containing the top 5 digrams together with their absolute and relative frequencies. Output the latter rounded to a precision of 6 decimal places. If two digrams should have the same frequency, sort them in (ASCII) lexicographical order. Output a blank line after each test case.
 
Sample Input
2 Take a look at this!! !!siht ta kool a ekaT 5 P=NP Authors: A. Cookie, N. D. Fortune, L. Shalom Abstract: We give a PTAS algorithm for MaxSAT and apply the PCP-Theorem [3] Let F be a set of clauses. The following PTAS algorithm gives an optimal assignment for F: 0
Sample Output
 a 3 0.073171
!! 3 0.073171
a  3 0.073171
 t 2 0.048780
oo 2 0.048780
 
 
 a 8 0.037209
or 7 0.032558
.   5 0.023256
e  5 0.023256
al  4 0.018605
 
题意:输入n行字符串,两个字符为一组;统计他们出现的频率,输出频率的前五位;频率相同按字典序输出;
 
AC代码:

 #include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int main()
{
int dp[][]={};//辅助数组。
char m[];//对字符串的输入
string str;//合成字符的存储;
int max=;//存储最大的次数
int n;//存储行数;
int j,i;//循环变量;
int leng;//存储总长度;
char a,b;
while(cin>>n)
{
gets(m);//录入n后的回车;
if(n==)break;//当n等于0是跳出;
memset(dp,,sizeof(dp));
gets(m);//录入第一行;
str=m;//存入str中
for(i=;i<=n;i++)
{
gets(m);//录入第i行;
str+=m;//存入str中;
}
leng=str.length();//读出str的长度;
for(i=;i<=leng-;i++)//逐个检测;
{
dp[str[i]][str[i+]]++;
}
max=;
double sum=;
for(i=;i<;i++)
{
for(j=;j<;j++)
{
if(dp[i][j]>max)max=dp[i][j];
sum+=dp[i][j];
}
}
n=;
while(max)
{
for(i=;i<;i++)
{
for(j=;j<;j++)
{
if(dp[i][j]==max)
{
a=i;
b=j;
cout<<a<<b<<" "<<max<<" ";
printf("%.6f\n",max/sum);
n++;
}
if(n==)break;//输出5组停止
}
if(n==)break;//输出5组停止
}
max--;
if(max==||n==)break;//输出5组停止,输出不够5组停止;
}
cout<<endl;//每个样例输出结束后输出一行空格;
}
return ;
}
 

杭电1002 Etaoin Shrdlu的更多相关文章

  1. 杭电 1002 A + B Problem II【大数相加】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 解题思路:就是把大的数用数组存放起来,像小学的时候用竖式加法来算两个数相加那样算: 反思:思路很 ...

  2. A + B Problem II(杭电1002)

    /*A + B Problem II Problem Description I have a very simple problem for you. Given two integers A an ...

  3. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  4. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  5. 杭电ACM刷题(1):1002,A + B Problem II 标签: acmc语言 2017-05-07 15:35 139人阅读 评

    最近忙于考试复习,没有多少可供自己安排的时间,所以我利用复习之余的空闲时间去刷刷杭电acm的题目,也当对自己编程能力的锻炼吧. Problem Description I have a very si ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  8. 杭电acm习题分类

    专注于C语言编程 C Programming Practice Problems (Programming Challenges) 杭电ACM题目分类 基础题:1000.1001.1004.1005. ...

  9. 2017杭电ACM集训队单人排位赛 - 6

    2017杭电ACM集训队单人排位赛 - 6 排名 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 59 1 X X 1 1 X X 0 1 ...

随机推荐

  1. POJ 1118 Lining Up

    枚举,排序. 先将所有点按双关键字排序,然后枚举线的顶点$P$,剩余的点以$P$为中心进行极角排序,可以取个$gcd$,这样一样的点就排在一起了,然后统计一下更新答案. #pragma comment ...

  2. [河南省ACM省赛-第四届] 表达式求值(nyoj 305)

    栈的模拟应用: #include<iostream> #include<cstdio> #include<cstring> #include<string&g ...

  3. git 基本的操作

      查看分支:git branch   查看所有分支:git branch -a   删除分支:git branch -d <name>   创建分支:git branch <nam ...

  4. ios 关于tableview小技巧

    第一个:cell中的分割线不顶头 首先在viewDidLoad方法加入以下代码: if ([self.tableView respondsToSelector:@selector(setSeparat ...

  5. android教学大纲

    android班 教学大纲 个小时 次课:Android开发环境搭建及工具介绍 Android系统简介 Android开发环境简介及搭建 AndroidStudio提供的工具组件 次课:第一个Andr ...

  6. HDU 5572 An Easy Physics Problem (计算几何+对称点模板)

    HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...

  7. sudo命令出错 must set be suid

    特殊权限 4,2 ,1 4  suid,控制用户执行的文件,以文件所属用户的身份执行.当一个可执行的文件拥有suid时,会将文件拥有者的x位变成s(---s--x--x),这时称为set uid,简写 ...

  8. Python3与Python2的区别汇总

    1.print 在Python3.0  是一个函数,正确输入应该是:print (3x) 2.raw_input 在Python3.0改成input

  9. C#动态编程

    class Program { static void Main(string[] args) { Test(); } public static void Test() { //声明代码的部分 Co ...

  10. HomeBrew 安装 PHP7.1(开发笔记)

    HomeBrew 安装 PHP7.1 $ brew update $ brew tap homebrew/dupes $ brew tap homebrew/php $ brew update $ b ...