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. Unity3DGUI:人物能量条

  2. Linux下服务器环境的搭建和配置之一——Apache篇

    最近一个多月(2016-06-20开始至今),一直在忙海外广告平台FAQ系统的开发,既要负责服务器环境的搭建,又要写前端,还要写后台和数据库,甚至还要考虑产品需求和设计.所以是一个很大的挑战,对自身也 ...

  3. 关于UI_USER_INTERFACE_IDIOM() & UIDevice.model

    使用 UI_USER_INTERFACE_IDIOM() 进行区分 (ios 3.2 >=) 无法区分iphone和ipod if (UI_USER_INTERFACE_IDIOM() == U ...

  4. Sql Server中三种字符串合并方法的性能比较

    文章来自:博客园-DotNet菜园 最近正在处理一个合并字符吕的存储过程,在一个测试系统的开发中,要使用到字符串合并功能,直接在Sql中做.示例:有表內容﹕名称  內容1     abc1      ...

  5. innodb更改行格式,系统盘占用急剧升高

    #大表引擎修改后,数据量较myisam引擎表大很多,对存储的行格式修改后,数据量减小. #备库修改时,由于服务器时间较早,系统盘20G,突然收到/磁盘空间占比89%的报警,立即将修改中断,恢复正常 # ...

  6. SQL Server 2008新特性——更改跟踪

    在大型的数据库应用中,经常会遇到部分数据的脱机和多个数据库的合并问题.比如现在有一个全省范围使用的应用程序,每个市都部署了单独的相同的应用程序服务器和数据库服务器,每个月需要将全省所有市的数据全部汇总 ...

  7. Myeclipse2014中,新建部署Maven项目

    一.环境 1.1 myeclipse2014 1.2 maven3.2.1 1.3 jdk1.7 上述环境配置可参照我之前编写的maven搭建方面的文档.本文着重介绍myeclipse2014下mav ...

  8. mysql修改编码

    1.查看当前编码 2.设置utf8mb4编码(也可以是其他),修改my.cnf或my.ini

  9. .net通过WCF调用java发布的服务,获取数据

    功能描述 java作为后台,连接数据库获取数据,然后发布SOAP services,让.net平台通过WCF进行引用. 实现步骤 1.在项目特定文件夹下,右键->添加服务引用,输入服务的url地 ...

  10. 第三天 函数 三元运算 lambda表达式 内置函数 文件操作

    面向过程: 直接一行一行写代码,遇到重复的内容复制黏贴. 不利于代码阅读 代码没有复用 面向对象 将代码块定义为函数,以后直接调用函数 增强了复用性 函数的定义方法 def 函数名(传递参数): 函数 ...