Problem 2091 播放器 模拟问题 I never stop loving you, but I just don't want anybody to see it any more.
2013-11-04 20:19
507 查看
Problem 2091 播放器
Accept: 251 Submit: 853
Time Limit: 1000 mSec Memory Limit : 32768 KB
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Problem Description
shadow喜欢听音乐,于是v11自己写了个播放器送给了shadow,这个播放器有一个播放列表,一个“下一首”按钮,一个“上一首”按钮,还有一个播放记录。一开始播放器会播放播放列表中的第一首歌,当按下“下一首”按钮时,它会播放当前歌曲在播放列表中的下一首歌,若当前歌曲就是播放列表中的最后一首歌时,它仍会播放播放列表中的最后一首歌;当按下“上一首”按钮时,它会清除播放记录中的最后一首歌,并播放清除后播放记录中的最后一首歌,若清除后播放记录为空,则播放播放列表中的第一首歌;当按下播放列表中的某一首歌曲,它会播放该首歌曲。
任何时候,当播放器播放一首歌时,如果该歌曲与播放记录中的最后一首不同或者播放记录为空,便将该歌曲添加到播放记录中成为最后一首。
现在shadow对播放器进行了一系列操作,那么你能告诉我shadow进行每一个操作后,播放器在播放哪首歌吗?
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Input
输入数据第一行包含一个整数T,表示测试数据的组数。对于每组测试数据:第一行包含两个整数n( 0 < n <= 500 )、m( 0 < m <= 10000),分别表示播放列表中有n首歌曲,shadow进行了m项操作,播放列表中歌的编号依次为1,2,3……n 。
接下来m行,每行为以下三种形式之一:
PRE 表示按下了“上一首”按钮。
PLAY x 其中x为一个整数( 0 < x <= n ),表示按下了播放列表中的第x首歌。
NEXT 表示按下了“下一首”按钮。
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Output
对于每组数据:输出m行,每行一个整数,表示执行了一项操作后播放器正在播放的歌曲。
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Sample Input
15 10PRENEXTPLAY 5NEXTPLAY 5PLAY 3NEXTPREPREPRE
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Sample Output
1255534352
![](http://acm.fzu.edu.cn/image/prodesc.gif)
Source
福州大学第九届程序设计竞赛这个题目中的审题是个问题,现在就让我来解释下歌曲究竟是怎么走的,我们在用到
PRE时,假如是第一的话,就播放第一个,否则就前一个了,NEXT,如果是最后一个,还是播放自己,否则就是下一个了,play的话在曲目加上它就是了,然后播放它,用num当做指针来数到底到了哪一首,就是了。
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int n,m,i,j,t,k; int a[10010]; int num; char s[10]; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); num=1; a[num]=1; for(i=1;i<=m;i++) { scanf("%s",s); //cout<<s<<endl; if(strcmp(s,"PRE")==0) { if(num==1) { a[num]=1; // printf("fdhjk"); printf("%d\n",a[num]); } else { printf("%d\n",a[num-1]); num--; } } else if(strcmp(s,"NEXT")==0) { if(a[num]==n) { //printf("aaa"); printf("%d\n",a[num]); } else { //printf("cccc"); printf("%d\n",a[num]+1); a[num+1]=a[num]+1; num++; } } else { scanf("%d",&k); if(a[num]!=k) { a[num+1]=k; num++; } //printf("fdfsdfsfdsfs"); printf("%d\n",a[num]); } } } return 0; }
相关文章推荐
- iOS 解决The file couldn’t be opened because you don’t have permission to view it.问题解决
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- This is it——I just can't stop loving you
- C语言——实例032 Press any key to change color, do you want to try it. Please hurry up!
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- 【 ac38 iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- Don’t predict; create the 2014 you want to see
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- 解决The file “FWLifeApp” couldn’t be opened because you don’t have permission to view it.问题
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it. 当引入第三方
- Press any key to change color, do you want to try it. Please hurry up!
- 【iOS问题】The file “XXX.app” couldn’t be opened because you don’t have permission to view it.
- the file “XXX” could not be opened because you don't have permission to view it问题
- 使用水晶报表11.5 问题 is already open. Do you want to close it?
- Just a test to see if any thing is ok or not
- tomcat filewatchdog but has failed to stop it原因以及解决方法
- I don’t want to see another “using namespace xxx;” in a header file ever again
- I don’t want to see another “using namespace xxx;” in a header file ever again
- iOS报错 - If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variabl