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) 收藏的更多相关文章

  1. 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 ...

  2. iOS 消息推送原理及实现总结 分类: ios技术 2015-03-01 09:22 70人阅读 评论(0) 收藏

    在实现消息推送之前先提及几个于推送相关概念,如下图: 1. Provider:就是为指定IOS设备应用程序提供Push的服务器,(如果IOS设备的应用程序是客户端的话,那么Provider可以理解为服 ...

  3. 动态链接库(DLL) 分类: c/c++ 2015-01-04 23:30 423人阅读 评论(0) 收藏

    动态链接库:我们经常把常用的代码制作成一个可执行模块供其他可执行文件调用,这样的模块称为链接库,分为动态链接库和静态链接库. 对于静态链接库,LIB包含具体实现代码且会被包含进EXE中,导致文件过大, ...

  4. 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 ...

  5. HDU 2040 亲和数 [补] 分类: ACM 2015-06-25 23:10 10人阅读 评论(0) 收藏

    今天和昨天都没有做题,昨天是因为复习太累后面忘了,今天也是上午考毛概,下午又忙着复习计算机图形学,晚上也是忘了结果打了暗黑3,把暗黑3 打通关了,以后都不会玩太多游戏了,争取明天做3题把题目补上,拖越 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. iOS开发:创建真机调试证书 分类: ios相关 2015-04-10 10:22 149人阅读 评论(0) 收藏

    关于苹果iOS开发,笔者也是从小白过来的,经历过各种困难和坑,其中就有关于开发证书,生产证书,in_house证书,add_Hoc证书申请过程中的问题,以及上架发布问题.今天就着重说一下关于针对于苹果 ...

随机推荐

  1. 安装 nodejs,npm,pm2

    一:需要安装组件: nodejs,npm,pm2 安装epel 源: rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel ...

  2. ASI接口

    Asynchronous Serial Interface ,异步串行接口,用于传送码流的一个标准DVB接口. 在目前的DVB-C系统设备的传输接口有两种MPEG2视频码流传输接口标准:异步串行接口A ...

  3. 使用Amoeba实现mysql读写分离机制

    Amoeba的实用指南 http://docs.hexnova.com/amoeba/ 如何实现mysql读写分离 : 通常来说有两种方式: 1,应用程序层实现 2,中间件层实现 应用层实现 应用层实 ...

  4. python 下载图片的方法

    a='http://wx1.sinaimg.cn/mw600/006HOayNgy1fqjdi2nxohj32pw3o8x6s.jpg'  #图片下载地址   ( 这里改成 文件txt地址)w='/U ...

  5. Java-Runoob-高级教程-实例-字符串:01. Java 实例 – 字符串比较

    ylbtech-Java-Runoob-高级教程-实例-字符串:01. Java 实例 – 字符串比较 1.返回顶部 1. Java 实例 - 字符串比较  Java 实例 以下实例中我们通过字符串函 ...

  6. 利用spring的ApplicationListener实现springmvc容器的初始化加载

    1.我们在使用springmvc进行配置的时候一般初始化都是在web.xml里面进行的,但是自己在使用的时候经常会测试一些数据,这样就只有加载spring-mvc.xml的配置文件来实现.为了更方便的 ...

  7. Golang基础学习总结

    转自:http://blog.csdn.net/yue7603835/article/details/44264925 1.不支持继承.重载 ,比如C++.Java的接口,接口的修改会影响整个实现改接 ...

  8. Python——截取web网页长图

    # -*- coding: utf8 -*-import timeimport xlrdfrom selenium import webdriver def read_excel(filename): ...

  9. 20165233 Java第七、十章学习总结

    20165233 2017-2018-2 <Java程序设计>第五周学习总结 教材学习内容总结 ch07 内部类:Java支持在一个类中声明另一个类,这样的类称为内部类,而包含内部类的类称 ...

  10. PowerDesigner软件的使用

    1. 报错:Could not Initialize JavaVM 的解决方案: powerDesigner不支持x64JDK,ok.安装32位. 仅仅是安装一下,不要做任何配置.......关闭po ...