ZOJ3700 Ever Dream 2017-04-06 23:22 76人阅读 评论(0) 收藏
Ever Dream
Time Limit: 2 Seconds Memory Limit: 65536 KB
"Ever Dream" played by Nightwish is my favorite metal music. The lyric (see Sample Input) of this song is much more like a poem. Every people may have their own interpretation for this
song depending on their own experience in the past. For me, it is a song about pure and unrequited love filled with innocence, willingness and happiness. I believe most people used to have or still have a long story with someone special or something special.
However, perhaps fatefully, life is totally a joke for us. One day, the story ended and became a dream in the long night that would never come true. The song touches my heart because it reminds me the dream I ever had and the one I ever loved.
Today I recommend this song to my friends and hope that you can follow your heart. I also designed a simple algorithm to express the meaning of a song by several key words. There are
only 3 steps in this algorithm, which are described below:
Step 1: Extract all different words from the song and counts the occurrences of each word. A word only consists of English letters and it is case-insensitive.
Step 2: Divide the words into different groups according to their frequencies (i.e. the number of times a word occurs). Words with the same frequency belong to the same group.
Step 3: For each group, output the word with the longest length. If there is a tie, sort these words (not including the words with shorter length) in alphabetical order and output the penultimate one. Here "penultimate" means the second to
the last. The word with higher frequency should be output first and you don't need to output the word that just occurs once in the song.
Now given the lyric of a song, please output its key words by implementing the algorithm above.
Input
The first line of input is an integer T (T < 50) indicating the number of test cases. For each case, first there is a line containing the number n (n <
50) indicating that there are n lines of words for the song. The following n lines contain the lyric of the song. An empty line is also counted as a single line. Any ASCII code can occur in the lyric. There will be at most 100 characters
in a single line.
Output
For each case, output the key words in a single line. Words should be in lower-case and separated by a space. If there is no key word, just output an empty line.
Sample Input
1
29
Ever felt away with me
Just once that all I need
Entwined in finding you one day Ever felt away without me
My love, it lies so deep
Ever dream of me Would you do it with me
Heal the scars and change the stars
Would you do it for me
Turn loose the heaven within I'd take you away
Castaway on a lonely day
Bosom for a teary cheek
My song can but borrow your grace Come out, come out wherever you are
So lost in your sea
Give in, give in for my touch
For my taste for my lust Your beauty cascaded on me
In this white night fantasy "All I ever craved were the two dreams I shared with you.
One I now have, will the other one ever dream remain.
For yours I truly wish to be."
Sample Output
for ever with dream
题目的意思是按单词词频分组,从频率最大的组开始,输出长度最大的单词没如果长度最大不唯一,则按字典序排序输出倒数第二个,只出现一次的不输出
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cctype>
#include <sstream>
#include <climits>
#include <unordered_map> using namespace std; #define LL long long
const int INF=0x3f3f3f3f; bool cmp(string a,string b)
{
if(a.size()==b.size())return a<b;
else return a.size()<b.size();
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
cin>>n;
getchar();
string line;
unordered_map<string,int> mp;
while(n--)
{
getline(cin,line);
auto it=begin(line);
for(; it!=end(line); it++)
if(!isalpha(*it))*it=' ';
else *it=tolower(*it);
stringstream ss(line);
string s;
while(ss>>s)
{
if(mp.count(s))mp[s]++;
else mp[s]=1;
}
}
auto it=begin(mp);
vector<string> v[120];
for(; it!=end(mp); it++)
{
string s=it->first;
if(it->second==1)continue;
v[it->second].push_back(s);
}
bool flag=0;
for(int i=100; i>0; i--)
{
int sz=v[i].size();
if(!sz)continue;
sort(begin(v[i]),end(v[i]),cmp);
if(sz==1){if(flag)cout<<" ";cout<<*(end(v[i])-1);}
else
{
if(flag)cout<<" ";
if(v[i][sz-1].size()==v[i][sz-2].size())cout<<v[i][sz-2];
else cout<<v[i][sz-1];
}
flag=1;
}
cout<<endl;
}
return 0;
}
ZOJ3700 Ever Dream 2017-04-06 23:22 76人阅读 评论(0) 收藏的更多相关文章
- ZOJ2482 IP Address 2017-04-18 23:11 44人阅读 评论(0) 收藏
IP Address Time Limit: 2 Seconds Memory Limit: 65536 KB Suppose you are reading byte streams fr ...
- iOS 消息推送原理及实现总结 分类: ios技术 2015-03-01 09:22 70人阅读 评论(0) 收藏
在实现消息推送之前先提及几个于推送相关概念,如下图: 1. Provider:就是为指定IOS设备应用程序提供Push的服务器,(如果IOS设备的应用程序是客户端的话,那么Provider可以理解为服 ...
- 动态链接库(DLL) 分类: c/c++ 2015-01-04 23:30 423人阅读 评论(0) 收藏
动态链接库:我们经常把常用的代码制作成一个可执行模块供其他可执行文件调用,这样的模块称为链接库,分为动态链接库和静态链接库. 对于静态链接库,LIB包含具体实现代码且会被包含进EXE中,导致文件过大, ...
- NYOJ-235 zb的生日 AC 分类: NYOJ 2013-12-30 23:10 183人阅读 评论(0) 收藏
DFS算法: #include<stdio.h> #include<math.h> void find(int k,int w); int num[23]={0}; int m ...
- HDU 2040 亲和数 [补] 分类: ACM 2015-06-25 23:10 10人阅读 评论(0) 收藏
今天和昨天都没有做题,昨天是因为复习太累后面忘了,今天也是上午考毛概,下午又忙着复习计算机图形学,晚上也是忘了结果打了暗黑3,把暗黑3 打通关了,以后都不会玩太多游戏了,争取明天做3题把题目补上,拖越 ...
- HDU 2034 人见人爱A-B 分类: ACM 2015-06-23 23:42 9人阅读 评论(0) 收藏
人见人爱A-B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU 2035 人见人爱A^B 分类: ACM 2015-06-22 23:54 9人阅读 评论(0) 收藏
人见人爱A^B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDU2033 人见人爱A+B 分类: ACM 2015-06-21 23:05 13人阅读 评论(0) 收藏
人见人爱A+B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- iOS开发:创建真机调试证书 分类: ios相关 2015-04-10 10:22 149人阅读 评论(0) 收藏
关于苹果iOS开发,笔者也是从小白过来的,经历过各种困难和坑,其中就有关于开发证书,生产证书,in_house证书,add_Hoc证书申请过程中的问题,以及上架发布问题.今天就着重说一下关于针对于苹果 ...
随机推荐
- Android wm指令用法详解
wm 是查看和设置显示信息的指令,此指令只能临时调试使用. wm:查看 wm 指令信息 $ adb shell root@rk3288:/ # wm wm usage: wm [subcommand] ...
- 【android】SDK环境变量配置
Android SDK: Android SDK提供了你的API库和开发工具构建,测试和调试应用程序,Android.简单来讲,Android SDK 可以看做用于开发和运行Android应用的一个软 ...
- Oracle本地网络服务名配置
1.安装Oracle 11G Client后可以在开始菜单中找到 选择NETCA->本地网络服务名配置 选择添加本地网服务名配置 这里的服务名:指的是也就是数据库名 在网络中架设C/S 客户端选 ...
- python3 关联规则Apriori代码模版
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from numpy import * def loadDataSet(): return [['a', ...
- [转][C#]压缩解压缩类 GZipStream
本文来自:https://msdn.microsoft.com/zh-cn/library/system.io.compression.gzipstream(v=vs.100).aspx using ...
- 20181123_SQL Server 2008_找出以逗号分隔的字符串中最大的数字
--select [dbo].[Fun_GetMaxNum]('棉 20%,麻 190%,涤纶60%') CREATE FUNCTION [dbo].[Fun_GetMaxNum] ( @StrAll ...
- All sentinels down, cannot determine where is mymaster master is running...
修改配置的哨兵文件 vim /sentinel.conf 将保护模式关闭
- Selenium2+python自动化62-jenkins持续集成环境搭建
前言 selenium脚本写完之后,一般是集成到jenkins环境了,方便一键执行. 一.环境准备 小编环境: 1.win10 64位 2.JDK 1.8.0_66 3.tomcat 9.0.0.M4 ...
- OpenMP 旅行商问题,静态调度
▶ <并行程序设计导论>第六章中讨论了旅行商,分别使用了 MPI,Pthreads,OpenMP 来进行实现,这里是 OpenMP 的代码,分为静态调度(每个线程分分配等量的搜索人物)和动 ...
- delphi XE8 NetHTTPRequest NetHTTPClient
delphi xe8 推出2个新http控件,NetHTTPRequest.NetHTTPClient 可以调用ASP.Net 一般应用程序获取网页数据,用旧的控件idhttp控件也可以,推荐用新的这 ...