题目来源 http://acm.ccniit.com/problem.php?cid=1199&pid=20
一.题目描述
stone非常喜欢听歌,尤其雅尼的夜莺是他的最爱,每次听着夜莺的旋律 和 别人注释的意境(写在歌词文件里)总会感觉很舒服,stone非常好奇歌词是怎么写的,所以打开了歌词文件lrc,因为夜莺的歌词文件不是很适合阅读,所以在此就以gala 的 Young For You 来做 范例吧
[00:05.99]young for you
[00:15.99]Gala
[00:25.99]by: Cwind
[00:32.99]
[00:35.99]sunday's coming i wanna drive my car
[00:39.70]to your apartment with present like a star
[00:43.69]forecaster said the weather may be rainy hard
……
看了歌词文件里面的内容,stone 有了一个想法就是写一个歌词显示器来模拟一下,不过因为一些众所周知的原因,stone 觉得还是让你们写会比较不错。
Input
首先输入歌词文件,当输入 [end]的时候表示歌词输入结束了,接下来会有一个数字n(n<=10)表示接下来有n次询问,每次询问会输入一个时间 让 歌词显示器来显示这个时间点这首歌需要显示什么歌词
有多份歌词,数据处理至文件结尾
Output
每次询问会输入一个时间 让 歌词显示器来显示这个时间点这首歌需要显示什么歌词
Sample Input Copy
[00:05.99]young for you
[00:15.99]Gala
[00:25.99]by: Cwind
[00:32.99]
[00:35.99]sunday's coming i wanna drive my car
[00:39.70]to your apartment with present like a star
[00:43.69]forecaster said the weather may be rainy hard
[end]
5
00:06.00
00:01.00
00:15.99
00:33.00
00:36.00
Sample Output Copy
young for you
Gala
sunday's coming i wanna drive my car
二.解题思路
每一时刻的歌词都不同,map<int,string> int存六位数时间,string存歌词 输入[end]准备输出,从大到小找到最先大于等于的时间直接输出。
三.代码
#include<bits/stdc++.h>
using namespace std;
map<int,string>q;
vector<int>p;
int main()
{ string s;int n,m,num,t=0,k;
while (getline(cin,s))
{ if (s=="[end]"){sort(p.begin(),p.end());
scanf("%d",&m);
while (m--)
{ cin>>s;
n=(s[0]-'0')*100000+(s[1]-'0')*10000+(s[3]-'0')*1000+(s[4]-'0')*100+(s[6]-'0')*10+s[7]-'0';//printf("%d\n",n);
if (n>=p[0])
{
for (int i = p.size()-1; i>=0 ; --i) {
if (n>=p[i])
{
cout<<q[p[i]]<<endl;break;
}
}
}
else printf("\n");
}p.clear();continue;
}
num=(s[1]-'0')*100000+(s[2]-'0')*10000+(s[4]-'0')*1000+(s[5]-'0')*100+(s[7]-'0')*10+s[8]-'0';
s=s.erase(0,10);q[num]=s;p.push_back(num);// 将输入的字符串存进vector
}
}