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证书申请过程中的问题,以及上架发布问题.今天就着重说一下关于针对于苹果 ...
随机推荐
- 解决:win8.1 oepnvpn客户端 redirect-gateway def1无效,自动获取的IP没有网关问题
解决:win8.1 oepnvpn客户端 redirect-gateway def1无效,自动获取的IP没有网关问题 该问题是操作系统权限问题,需要将程序设置为以管理员模式运行和以windows7兼容 ...
- 【转】httpservlet 文章
HttpServlet类 ellisonDon 2012-10-25 12:42 阅读:2015 评论:0 HttpServlet的功能 ellisonDon 2012-10-25 11:02 ...
- POJ 2777-题解
一.题意 给你一排N个格子,M种颜色,P个操作.有两种操作:(1)C A B D:把[A, B]区间内的所有格子涂成颜色D.(2)P A B:输出[A, B]区间内的颜色的种类数.注意,初始颜色为1. ...
- window server2008 r2 限制远程访问用户数量
在服务器端设置 修改组策略 1,开始-运行-gpedit.msc-计算机配置-管理模板-Windows组件-远程桌面服务-远程桌面会话主机-限制连接数量-开启并改为1
- linux编程vim设置
linux环境下c网络编程vim编辑工具设置,包括自动缩进,tab键对齐等.
- 43.国际化-app级别的资源文件
转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 在src目录下建立两个资源文件,取名为myapp_en_US.propert ...
- oracle执行sql文件
oracle执行sql文件 在PL/SQL中直接用command window执行就可以了: PL/SQL developer----->File------>New---->com ...
- auto_ptr 浅析(转)
auto_ptr是C++标准库中(<utility>)为了解决资源泄漏的问题提供的一个智能指针类模板(注意:这只是一种简单的智能指针) auto_ptr的实现原理其实就是RAII,在构造的 ...
- Visual Studio 使用Web Deploy发布项目
工具:Web Deploy 3.6 点击下载 (强烈推荐使用独立的Web Deploy 安装包安装) 使用 Web Platform Installer 安装 Web Deploy(3.5,3.6都安 ...
- Selenium+TestNG+Maven 搭建
Java环境配置 Eclipse配置TestNG Eclipse配置Maven pom.xml文件相关配置,添加依赖selenium和TestNg的jar包 <!-- https://mvnre ...