描述

Institute of Computational Linguistics (ICL), Peking University is an interdisciplinary institute of science and liberal arts, it focuses primarily on the fundamental researches and applications of language information processing. The research of ICL covers a wide range of areas, including Chinese syntax, language parsing, computational lexicography, semantic dictionaries, computational semantics and application systems.

Professor X is working for ICL. His little daughter Jane is 9 years old and has learned something about programming. She is always very interested in her daddy's research. During this summer vacation, she took a free programming and algorithm course for kids provided by the School of EECS, Peking University. When the course was finished, she said to Professor X: "Daddy, I just learned a lot of fancy algorithms. Now I can help you! Please give me something to research on!" Professor X laughed and said:"Ok, let's start from a simple job. I will give you a lot of text, you should tell me which phrase is most frequently used in the text."

Please help Jane to write a program to do the job.

输入

There are no more than 20 test cases.

In each case, there are one or more lines of text ended by a line of "####". The text includes words, spaces, ','s and '.'s. A word consists of only lowercase letters. Two adjacent words make a "phrase". Two words which there are just one or more spaces between them are considered adjacent. No word is split across two lines and two words which belong to different lines can't form a phrase. Two phrases which the only difference between them is the number of spaces, are considered the same.

Please note that the maximum length of a line is 500 characters, and there are at most 50 lines in a test case. It's guaranteed that there are at least 1 phrase in each test case.

输出

For each test case, print the most frequently used phrase and the number of times it appears, separated by a ':' . If there are more than one choice, print the one which has the smallest dictionary order. Please note that if there are more than one spaces between the two words of a phrase, just keep one space.

样例输入

above,all ,above all good at good at good
at good at above all me this is
####
world hello ok
####

样例输出

at good:3
hello ok:1

#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <ctime>
#include <cstring>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#define LL long long
#define Pr pair<int,int>
#define fread(ch) freopen(ch,"r",stdin)
#define fwrite(ch) freopen(ch,"w",stdout)
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-8;
const int maxn = 11234;
map <string,int> mp;
char as[555];
char pre[555];
char now[555];
char tmp[555];
char str[555];
int ans;
bool Ischar(char ch)
{
return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z');
}
int sread(int &pos)
{
while(str[pos] && !Ischar(str[pos])) ++pos;
if(!str[pos]) return 0;
int p1 = 0;
while(str[pos] && Ischar(str[pos])) now[p1++] = str[pos++];
now[p1] = 0;
while(str[pos] && str[pos] == ' ') ++pos;
return (str[pos] && Ischar(str[pos]))? 1: -1;
}
int main()
{
while(gets(str))
{
mp.clear();
ans = -1;
while(str[0] != '#')
{
int pos = 0;
int p1,p2;
pre[1] = '.';
pre[2] = 0;
int k;
while((k = sread(pos)))
{
//                printf("%d ",pos);
//                printf("%s ",now);
//                printf("%d\n",k);
bool can = 1;
for(int i = 0; pre[i]; ++i)
{
if(!Ischar(pre[i]))
{
can = 0;
break;
}
}
if(can)
{
strcpy(tmp,pre);
int p1 = strlen(pre);
tmp[p1++] = ' ';
strcpy(tmp+p1,now);
mp[tmp]++;
if(ans < mp[tmp] || (ans == mp[tmp] && strcmp(as,tmp) > 0))
{
ans = mp[tmp];
strcpy(as,tmp);
}
}
if(k == 1) strcpy(pre,now);
else pre[0] = '.',pre[1] = 0;
}
gets(str);
}
printf("%s:%d\n",as,ans);
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct list
{
int d;
char ch[2][501];
}a[12500];
int cmp(struct list x,struct list y)
{
if(x.d>y.d)
{
return 1;
}
else if(x.d==y.d&&(strcmp(x.ch[0],y.ch[0])<0||(strcmp(x.ch[0],y.ch[0])==0&&strcmp(x.ch[1],y.ch[1])<0)))
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int i,i1,top=0;
char ch[501],s1[501],s2[501],flag;
while(gets(ch)!=NULL)
{
flag=0;
i1=0;
if(strcmp(ch,"####")==0)
{
sort(a,a+top,cmp);
printf("%s %s:%d\n",a[0].ch[0],a[0].ch[1],a[0].d);
top=0;
continue;
}
for(i=0;ch[i]!='\0';i++)
{
if(ch[i]==' '||ch[i]==','||ch[i]=='.')
{
if(flag==1&&i1!=0)
{
s2[i1]='\0';
for(i1=0;top>i1;i1++)
{
if(strcmp(a[i1].ch[0],s1)==0&&strcmp(a[i1].ch[1],s2)==0)
{
a[i1].d++;
break;
}
}
if(i1==top)
{
strcpy(a[i1].ch[0],s1);
strcpy(a[i1].ch[1],s2);
a[i1].d=1;
top++;
}
strcpy(s1,s2);
}
else if(flag==0&&i1!=0)
{
flag++;
s2[i1]='\0';
strcpy(s1,s2);
}
if(ch[i]==','||ch[i]=='.')
{
flag=0;
}
i1=0;
continue;
}
s2[i1]=ch[i];
i1++;
}
if(flag==1&&i1!=0)
{
s2[i1]='\0';
for(i1=0;top>i1;i1++)
{
if(strcmp(a[i1].ch[0],s1)==0&&strcmp(a[i1].ch[1],s2)==0)
{
a[i1].d++;
break;
}
}
if(i1==top)
{
strcpy(a[i1].ch[0],s1);
strcpy(a[i1].ch[1],s2);
a[i1].d=1;
top++;
}
strcpy(s1,s2);
}
}
return 0;
}

A Simple Job相关推荐

  1. RabbitMQ 入门系列(11)— RabbitMQ 常用的工作模式(simple模式、work模式、publish/subscribe模式、routing模式、topic模式)

    1. simple 模式 simple 模式是最简单最常用的模式 2. work 模式 work 模式有多个消费者 消息产生者将消息放入队列.生产者系统不需知道哪一个任务执行系统在空闲,直接将任务扔到 ...

  2. Simple NHibernate Architecture[from]

    原文地址:http://www.codeproject.com/aspnet/NHibernateArchitecture.asp Download source - 2,523.7 KB Intro ...

  3. HDU 1757 A Simple Math Problem

    Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x & ...

  4. Simple Dynamic Strings(SDS)源码解析和使用说明二

    在<Simple Dynamic Strings(SDS)源码解析和使用说明一>文中,我们分析了SDS库中数据的基本结构和创建.释放等方法.本文将介绍其一些其他方法及实现.(转载请指明出于 ...

  5. 《深入理解Android:Wi-Fi,NFC和GPS》章节连载[节选]--第六章 深入理解wi-Fi Simple Configuration...

    为什么80%的码农都做不了架构师?>>>    首先感谢各位兄弟姐妹们的耐心等待.本书预计在4月上市发售.从今天开始,我将在博客中连载此书的一些内容.注意,此处连载的是未经出版社编辑 ...

  6. A simple class to play sound on netcf (part 2)

    在实际测试中发现上一片文章(A simple class to play sound on netcf)中介绍的播放声音的类在pda中运行正常,但却无法在pc中工作,简单分析了一下原因,发现是dll的 ...

  7. Simple Transformer:用BERT、RoBERTa、XLNet、XLM和DistilBERT进行多类文本分类

    作者 | Thilina Rajapakse 译者 | Raku 编辑 | 夕颜 出品 | AI科技大本营(ID: rgznai100) [导读]本文将介绍一个简单易操作的Transformers库- ...

  8. Matplotlib可视化散点图、配置X轴为对数坐标、并使用线条(line)连接散点图中的数据点(Simple Line Plot with Data points in Matplotlib)

    Matplotlib可视化散点图.配置X轴为对数坐标.并使用线条(line)连接散点图中的数据点(Simple Line Plot with Data points in Matplotlib) 目录

  9. Comprehensive anticancer drug response prediction based on a simple cell line drug complex network m

    Comprehensive anticancer drug response prediction based on a simple cell line drug complex network m ...

  10. Could not fetch URL https://pypi.org/simple/pip/

    Could not fetch URL https://pypi.org/simple/pip/ 解决办法 更换pip安装源头成阿里云或清华的 在Windows%appdata%/pip/pip.in ...

最新文章

  1. NEC中标里斯本智慧城市项目 助力城市整体数字化变革
  2. Node.js 添加 C/C++ Addon
  3. Server Too Busy
  4. SQL性能优化应该考虑哪些?
  5. Uva 442 - Matrix Chain Multiplication(模拟)
  6. P2680-运输计划【LCA,树上差分,二分答案】
  7. NPM使用前设置和升级
  8. Linux系统:centos7下搭建Rocketmq4.3中间件,和监控台
  9. Linux 多线程可重入函数
  10. 熬了整整30天,java递归阶乘求和
  11. 区块链 以太坊 solidity 如何比较2个字符串相等
  12. 【PowerBuilder 9.0 使用时第一次遇到的错误 c0031】
  13. linux14.04镜像,ubuntu14.04 iso镜像下载
  14. 名词用作动词举例_名词作动词的句子
  15. 九、redis的删除机制
  16. 分布式三大利器之《消息队列》
  17. simulink/stateflow官方案例之自动变速器
  18. 用老版的python和pycharm好,还是新版的python和pycharm好?
  19. 如何编译DD-WRT
  20. 这里需要一个高端大气上档次的开头

热门文章

  1. mui ajax 文件上传,MUI的图片上传和压缩
  2. 仙逆网页服务器失败,全民仙逆闪退进不去了怎么办 闪退解决办法汇总
  3. 啊哈c语言答案1.3,啊哈C语言编程-第2课-让计算机开口说话
  4. idea 保存设置 新建项目_配置、创建IntelliJ IDEA Spring MVC 项目
  5. python 读取excel表格_python 对Excel表格的读取
  6. 公文字体字号标准2020_一文了解公文格式规范,图文并茂(建议收藏备用)
  7. matlab热度图确定色标_C++实现类似Matlab的colormap Jet(灰度图生成彩色热度图)
  8. iis php网站500错误原因_如何解决iis php 500错误问题
  9. 图片还原去遮挡_斗罗:这届coser太强,动画刚播出两天,战损三哥就被还原了...
  10. linux设备树例程,iTOP-iMX6-设备树内核-实时时钟RTC以及Linux-c测试例程