ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 A Simple Job
描述
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
题解没有QAQ
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
char ss[1000];
map<string,int>q;
map<string,int>::iterator it;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
string s;
while(cin.getline(ss,sizeof(ss)))
{
if(ss[0]=='#')
{
string x;
int p=0,cnt=0,p1=0;
for(int i=0;i<s.size();i++)
{
if(s[i]==' ')
{
cnt++;
p1=p;
p=i;
}
else if(s[i]==',')
{
cnt++;
if(cnt==1)
{
x="";
cnt=0;
}
p=i;
p1=i;
}
if(s[i]!=','&&cnt!=2)
{
x+=s[i];
}
if(cnt>=2)
{
q[x]++;
cnt=0;
if(s[i]==' ') i=p1;
x="";
}
}
int Max=0;
string y;
for(it=q.begin();it!=q.end();it++)
{
if(it->second>Max) y=it->first,Max=it->second;
}
cout<<y<<":"<<q[y]<<endl;
q.clear();
s="";
}
else
{
for(int i=0;i<strlen(ss);i++)
{
if(ss[i]=='.') ss[i]=',';
if(ss[i]==' ')
{
if(ss[i-1]==','||ss[i+1]==','||ss[i-1]==' ')
continue;
}
s+=ss[i];
}
s+=',';
}
}
return 0;
}
ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 A Simple Job的更多相关文章
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 The Book List
		
描述 The history of Peking University Library is as long as the history of Peking University. It was b ...
 - hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
		
#1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people coul ...
 - hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
		
#1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...
 - hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
		
#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...
 - hihoCoder 1578  Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
		
#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...
 - ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6
		
#1228 : Mission Impossible 6 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You must have seen the very famou ...
 - ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum
		
时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...
 - ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 i题 Minimum(线段树)
		
描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...
 - 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute
		
题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...
 
随机推荐
- sdutoj 2603 Rescue The Princess
			
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603 Rescue The Princess ...
 - 封装cookie  localStorage sessionStorage
			
var cookie = function(name, value, options) { if (typeof value !== 'undefined') { options = options ...
 - sql  表连接 join
			
inner join 和 join 的 区别 inner join 是内连接 ,查询出两边 都有的数据 join 是交叉 连接, 假设集合A={a, b},集合B={0, 1, 2},则两个集 ...
 - weka 文本分类(1)
			
一.初始化设置 1 jvm out of memory 解决方案: 在weka SimpleCLI窗口依次输入java -Xmx 1024m 2 修改配置文件,使其支持中文: 配置文件是在Weka安装 ...
 - 【crunch bang】 增加“菜单项”
			
[右键菜单]->[Settings]->[Openbox]->[GUI Menu Editor] 挑选合适的位置,增加[菜单项],编辑内容.
 - 详解Android AM命令
			
1.简介 在Android中,我们除了从界面上启动程序之外,还可以从命令行启动程序,如使用命令行工具am. am全称activity manager,是Android下非常实用命令,其代码在frame ...
 - redis面试题总结
			
1. 使用redis有哪些好处? (1) 速度快,因为数据存在内存中,类似于HashMap,HashMap的优势就是查找和操作的时间复杂度都是O(1) (2) 支持丰富数据类型,支持string,li ...
 - sql创建删除修改表的基本操作
			
1 建立表格 在建立好数据库以后,就可以根据储存资料的需求,使用SQL叙述建立所有需要的表格(table).建立表格的设定非常多,以建立"world.city"表格来说,它的叙述会 ...
 - datasnap 的线程池(转)
			
datasnap的线程池 新的datasnap使用INDY10的线程池.不管你知不知道,DATASNAP都是使用线程池了,这和MIDAS不同,MIDAS默认是没有线程池的. 跟踪INDY10线程池类T ...
 - 161107、spring异步调用,完美解决!
			
项目中,用户抢单,下单需要向对方推送消息,但是加上推送就会造成抢单和下单性能降低,反应变慢,因为抢单下单动作跟推送部分是同步的,现在想改成异步推送. 在Java应用中,绝大多数情况下都是通过同步的方式 ...