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. windows 如何查看端口占用进程ID 进程名称 强制结束进程

    1.查看指定端口的占用情况C:\>netstat -aon|findstr "9050" 协议    本地地址                     外部地址        ...

  2. linux关于ftp查看不到文件列表的问题

    今天配置linux服务器的ftp后,登录都正常,使用ftp工具登录后,所有目录都可以通过手工写路径访问,但是文件夹和文件列表看不到数据. 后来分析,总结原因得出结果是跟selinux有关,于是通过关闭 ...

  3. CSS背景图像的简单响应

    本文设有很多,最理想的解决方案,响应图像只是其中之一.我们建议您查看不同的方法,然后再选择一个特定的响应图像解决方案,包括这两个:如何避免重复下载响应图像中选择响应图像解决方案. 大家都在谈论的的sr ...

  4. 自动手动随便你 Win7驱动程序安装自己设

    Win7系统是非常智能方便的操作系统,可以自动安装硬件驱动程序,为用户提供了很多方便.但是并不是所有的驱动程序和硬件都能完美兼容,如果不合适就需要卸载了重新安装:还有一些朋友就习惯自己安装驱动,那么, ...

  5. [Python] numpy.ndarray.shape

    ndarray.shape Tuple of array dimensions. x = np.array([1, 2, 3, 4]) print x.shape #(4, ) y = np.zero ...

  6. Python开发一个堡垒机

    项目实战:运维堡垒机开发 前景介绍 到目前为止,很多公司对堡垒机依然不太感冒,其实是没有充分认识到堡垒机在IT管理中的重要作用的,很多人觉得,堡垒机就是跳板机,其实这个认识是不全面的,跳板功能只是堡垒 ...

  7. string ids=aduuids.Aggregate("", (m, n) => m + n+",").TrimEnd(',');

    string ids=aduuids.Aggregate("", (m, n) => m + n+",").TrimEnd(',');

  8. VB.Net与C# 的语法比较

    最近看代码或写代码时,经常把VB与C#的基本语法搞混,为方便查看,特对其异同进行对比: 變數初始化 VB.NET 自動將所有的變數初始化成 0 或 nothing.C# 在你未初始化變數之前不准你用該 ...

  9. 可视化库-Matplotlib-散点图(第四天)

    1. 画基本的散点图 plt.scatterdata[:, 0], data[:, 1], marker='o', color='r', label='class1', alpha=0.4) np.r ...

  10. 迷你MVVM框架 avalonjs 0.96发布

    本版本主要是性能优化与 fix BUG,改进如下: 处理notifySubscribers中的BUG,它在标准浏览器不会移除那些无用的视图刷新函数.详见这里 重构modelBindling.SELEC ...