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. URL 收录

    http://www.cnblogs.com/Olive116/p/3426957.html 地图控件 http://www.cnblogs.com/tugenhua0707/ 前端

  2. 智能家居入门DIY——【七、添加一个LCD12864吧】

    今天加了一个LCD12864,IC看说明上是ST7567,结果一顿U8g2,发现两个问题: 1.买的时候不知道是卖家写的我理解错了还是怎么了,反正是不出汉字的. 2.U8g2太大了…………占了uno的 ...

  3. MyBatis框架简介

    1.下载地址:下载地址:https://github.com/mybatis/mybatis-3/releases 2.MyBatis是什么? MyBatis 本是apache的一个开源项目iBati ...

  4. PyQt5系列教程(五)制作fastboot烧写器

    软硬件环境 Windows 7 Python 3.4.2 PyQt 5.5.1 PyCharm 5.0.2 前言 fastboot是针对Android设备的一种刷机方式,它比recovery更底层,刷 ...

  5. python推荐书籍

    推荐的python电子书 python学习路线图 优先级 入门:python核心编程 提高:python cookbook 其他 (1).数据分析师 需要有深厚的数理统计基础,但是对程序开发能力不做要 ...

  6. MyEclipse 配置Android环境

    eclipse https://www.eclipse.org/downloads/download.php?file=/oomph/epp/mars/R2/eclipse-inst-win64.ex ...

  7. Microsoft Office Professional Plus 2013全套

    Microsoft Office Professional Plus 2013全套产品,全激活版本 包括Access  Word  Excel  Powerpoint  Publisher  Skyd ...

  8. OpenCv dnn module -实时图像分类

    配置环境:OpenCv3.4, vs2013(x64),Win7.用OpenCv dnn module 实时检测摄像头,视频和图像的分类示例原代码为:https://docs.opencv.org/3 ...

  9. linux命令之scp远程文件复制

    scp是linux中功能最强大的文件传输命令,可以实现从本地到远程以及远程到本地的轻松文件传输操作.下面简单的讲解一些关于scp命令的操作,给有用的人一些参考: 首先是本地到远程的操作:操作的格式如下 ...

  10. 新手C#int.Parse、int.TryParse的学习2018.08.04

    int.Parse()用于将字符串转换为32为int类型,但是在遇到非数字或者类似1.545这种小数的时候会报错,后来采用了int.TryParse,这个在转换后会判断是否可以正常转换,若不能,会返回 ...