博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hihoCoder1385——A Simple Job(模拟)
阅读量:2344 次
发布时间:2019-05-10

本文共 3191 字,大约阅读时间需要 10 分钟。

描述

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

写的时候太冲动,很多情况没考虑,WA了好几次

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 10000005#define Mod 10001using namespace std;map
,int> hs;char s[5000];int main(){ string a,b; while(gets(s)) { int len=strlen(s); s[len]=' '; s[len+1]='\0'; if(s[0]!='#') { a=b=""; bool flag=false; for(int i=0; s[i]!='\0'; ++i) { if(s[i]==' '&&s[i+1]==' ') continue; if(s[i]>='a'&&s[i]<='z'&&!flag) a+=s[i]; if(s[i]>='a'&&s[i]<='z'&&flag) b+=s[i]; if(s[i]==' '&&!flag&&!a.empty()) { flag=true; continue; } if((s[i]==' '||s[i]==','||s[i]=='.')&&flag) { if(!b.empty()&&!a.empty()) { hs[make_pair(a,b)]++; //cout<
<<" "<<<" "<
<
,int>::iterator it=hs.begin(),ans; int ma=-1; for(; it!=hs.end(); ++it) { if(it->second>ma) { ma=it->second; ans=it; } } cout<
first.first<<" "<
first.second<<":"<
second<

转载地址:http://nvcvb.baihongyu.com/

你可能感兴趣的文章
UML总结(对九种图的认识和如何使用Rational Rose 画图)
查看>>
Java中使用HttpRequest获取用户真实IP地址端口
查看>>
easyUI下拉列表点击事件的使用
查看>>
js遍历map
查看>>
单例模式
查看>>
JDBC连接数据库核心代码
查看>>
java生成随机汉字
查看>>
Java反射的基本应用
查看>>
HTML5常用标签
查看>>
where 1=1影响效率以及having和where的区别
查看>>
资源链接
查看>>
注册中心Eureka页面添加用户认证
查看>>
spring源码
查看>>
上传jar包到nexus私服
查看>>
lambda和抽象类
查看>>
idea自定义文档注释模板
查看>>
Enterprise Architect 生成项目类图
查看>>
idea导出配置
查看>>
JVM学习资料收集
查看>>
Codility经典算法题之九:MissingInteger
查看>>