题解 | #MP3光标位置#

MP3光标位置

https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15

#include <stdio.h>
#include <string.h>

int Min(int a,int b){
    if(a>b) return b;
    return a;
}

int main() {
    int zongshu=0,n_cz=0,list_head=1,gb=1;
    char caozuo[101] = {0};

    scanf("%d\n%s",&zongshu,caozuo);
    n_cz = strlen(caozuo);

    for(int i=0;i<n_cz;i++){
        switch(caozuo[i]){
            case 'U':
            if((gb==list_head)&&(gb==1)){
                if(zongshu<4){
                    gb = zongshu;
                    break;
                }
                list_head = zongshu - 3;
                gb = zongshu;
                break;
            }
            if((gb==list_head)&&(zongshu>4)) list_head --;
            gb --;
            break;
            case 'D':
            if((gb==Min(list_head+3,zongshu))&&(gb==zongshu)){
                if(zongshu<4){
                    gb = 1;
                    break;
                }
                list_head = 1;
                gb = 1;
                break;
            }
            if((gb==Min(list_head+3,zongshu))&&(zongshu>4)) list_head ++;
            gb ++;
            break;
        }
    }
    if(zongshu<4){
        for(int i=0;i<zongshu;i++) printf("%d ",i+1);
        printf("\n%d",gb);
    }else
        printf("%d %d %d %d\n%d",list_head,list_head+1,list_head+2,list_head+3,gb);
}

全部评论

相关推荐

零零幺零零幺:至少再做一个项目,然后猛投小厂,不然有点难
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务