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. 用Python做SVD文档聚类---奇异值分解----文档相似性----LSI(潜在语义分析)

    转载请注明出处:电子科技大学EClab——落叶花开http://www.cnblogs.com/nlp-yekai/p/3848528.html SVD,即奇异值分解,在自然语言处理中,用来做潜在语义 ...

  2. C++类的实例化的两种方法

    C++ 类的实例化有两种方法: 直接定义对象: 先定义一个类:   class A { public: A(); virtual ~A(); ... ... };   类实现略. 用的时候: A a; ...

  3. 1、API

    基本API sectionsColor:['green','orange','red','grey'],//为每一层设置背景颜色 controlArrows:true,//是否显示幻灯片的左右按钮 v ...

  4. windows中操作文件和目录的函数

    1.文件操作函数       CreateFile();//创建或打开文件      ReadFile();//从文件读      WriteFile();//向文件写      SetFilePoi ...

  5. Qt出现常量有换行符的错误的解决方法

    可以使用 QString::fromLocal8Bit 来将本地字符编码转换为 Unicode 形式的 QString.

  6. 关于mongodb的一些笔记

    1.以服务的形式安装mongodb dos -- 进入到mongodb的bin目录下,执行 D:\mongodb\bin>mongod --logpath D:\mongodb\logs\mon ...

  7. 跳转到设置页面 与appstory

    //MARK:系统跳到应用设置页面 func systemMySet(){ let url = NSURL(string: UIApplicationOpenSettingsURLString) if ...

  8. cetos6 安装samba共享文件夹

    yum方式安装 yum install samba 修改配置文件 vim /etc/samba/smb.conf [global] comment = global workgroup = QFpay ...

  9. js 冒泡排序

    var arr = []; for(var i=0; i<100000; i++){ arr.push(parseInt(Math.random()*100)) }; var t1 = Date ...

  10. group by 和count 联合使用问题

    工作中要根据用户发布的产品数量来排序做分页,使用group by uid 用count(uid) 来统计的数量和想要的数量不正确. count统计的数量是被group by 分组以后每一组中数据的数量 ...