zoukankan      html  css  js  c++  java
  • FZU 2091 播放器

    简单模拟题,开个栈维护一下即可。

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<string>
    #include<algorithm>
    #include<stack>
    #include<iostream>
    using namespace std;
    
    stack<int>S;
    int n,m;
    int nowpos;//播放列表播放到哪一首
    
    void init()
    {
        nowpos=1;
        while(!S.empty()) S.pop();
    }
    
    void Pri(int nowpos)
    {
        printf("%d
    ",nowpos);
        if(S.empty()||nowpos!=S.top()) S.push(nowpos);
    }
    
    void PRE()
    {
        if(S.empty())
        {
            nowpos=1;
            Pri(nowpos);
        }
        else
        {
            S.pop();
            if(S.empty())
            {
                nowpos=1;
                Pri(nowpos);
            }
            else
            {
                nowpos=S.top();
                Pri(nowpos);
            }
        }
    }
    
    void PLAY(int num)
    {
        nowpos=num;
        Pri(nowpos);
    }
    
    void NEXT()
    {
        if(nowpos==n)
        {
            Pri(nowpos);
        }
        else
        {
            nowpos++;
            Pri(nowpos);
        }
    }
    
    void work()
    {
        char s[10];
        for(int i=0;i<m;i++)
        {
            scanf("%s",s);
            if(strcmp("PRE",s)==0) PRE();
            else if(strcmp("PLAY",s)==0)
            {
                int y;
                scanf("%d",&y);
                PLAY(y);
            }
            else if(strcmp("NEXT",s)==0) NEXT();
        }
    }
    
    
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d",&n,&m);
            init();
            work();
        }
        return 0;
    }
  • 相关阅读:
    cl编译器命令行调试问题
    西电计算机专业培养
    GCN代码实现
    GCN介绍
    cpu密集型任务及IO密集型任务,GIS,多进程及多线程
    骨架提取
    视频文件的一些属性
    空洞填充
    凸包,二值图家矩形框
    RGB图片取大于阈值部分
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5242604.html
Copyright © 2011-2022 走看看