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. js onblur 和 onkeyup 事件用法

    1. onblur 表示失去焦点时触发 2. onkeyup 表示键盘每输完一个字符之后触发,就是键盘上的按键被放开时. 例子如下: <!DOCTYPE HTML PUBLIC "-/ ...

  2. 第一百一十七节,JavaScript,DOM元素尺寸和位置

    学习要点: 1.获取元素CSS大小 2.获取元素实际大小 3.获取元素周边大小 本章,我们主要讨论一下页面中的某一个元素它的各种大小和各种位置的计算方式,以便更好的理解. 一.获取元素CSS大小 1. ...

  3. DP! | 不要怂!

    跟一个博客刷: http://blog.csdn.net/cc_again/article/details/25866971 一.简单基础dp 1.递推 HDU 2084 #include <b ...

  4. 自己通过反射写的一个属性copy类

    package com.xxx.beancopier; import java.lang.annotation.Documented; import java.lang.annotation.Elem ...

  5. linux下获取硬盘、内存、U盘大小及使用大小

    /* * 获取硬盘大小;内存大小;usb大小 */ #ifndef SYSINFOGET_H #define SYSINFOGET_H #include <stdio.h> //磁盘信息 ...

  6. jquery复选框操作

    $('input[type="checkbox"]').change(function(e) { var checked = $(this).prop("checked& ...

  7. Thrift框架简介

    功能:实现各个服务模块之间的跨语言.跨平台的通信,是RPC框架的一种,与dubbo类似. Thrift的应用原理: Thrift的部分功能相当于代码生成引擎,使用Thrift定义的语言编写*.Thri ...

  8. ie6的png24问题

    解决IE6的PNG透明JS插件 DD_belatedPNG 引:http://www.cnblogs.com/cobby/archive/2012/05/11/2495801.html IE6的PNG ...

  9. Python--变量作用域

    变量作用域: 一般在函数体外定义的变量成为全局变量,在函数内部定义的变量称为局部变量. 全局变量所有作用域都可读,局部变量只能在本函数可读 函数在读取变量时,优先读取函数本身自有的局部变量,再去读全局 ...

  10. redis11--java_jedis-test

    使用Java开发项目的时候使用Redis的话,目前有一些开源API可以使用.最常用的就是jedis,它提供了许多基于Java的对象和方法来调用Redis的指令.jedis的jar包下载地址http:/ ...