首页 > 其他 > 详细

MP3光标位置(HJ64)

时间:2020-08-02 22:04:46      阅读:143      评论:0      收藏:0      [点我收藏+]

一:解题思路

二:完整代码示例 (C++版和Java版)

C++代码:

#include <iostream>
#include <cstring>

using namespace std;

void selectSong(int nums, const char* str)
{
    int current = 1;
    int top = 1;
    int buttom = 4;
    int len = strlen(str);

    if (nums <= 4)
    {
        current = 1;
        top = 1;
        buttom = nums;

        for (int i = 0; i < len; i++)
        {
            if (str[i] == U)
            {
                if (current == 1)
                {
                    current = buttom;
                }
                else
                {
                    current--;
                }
            }
            else
            {
                if (current == buttom)
                    current = 1;
                else
                    current++;
            }
        }
    }
    else
    {
        for (int i = 0; i < len; i++)
        {
            if (str[i] == U)
            {
                if (current == 1)
                {
                    current = nums;
                    top = nums - 3;
                    buttom = nums;
                }
                else if (current == top)
                {
                    current--;
                    top--;
                    buttom--;
                }
                else
                    current--;
            }
            else
            {
                if (current == nums)
                {
                    current = 1;
                    top = 1;
                    buttom = 4;
                }
                else if (current == buttom)
                {
                    current++;
                    top++;
                    buttom++;
                }
                else
                    current++;
            }
        }
    }

    for (int i = top; i <= buttom; i++)
        cout << i << " ";
    cout << endl;

    cout << current << endl;
}

int main()
{
    int nums = 0;
    char str[100] = {};

    while (cin >> nums >> str)
    {
        selectSong(nums,str);
    }

    return 0;
}

 

MP3光标位置(HJ64)

原文:https://www.cnblogs.com/repinkply/p/13423189.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!