MP3游標位置(HJ64)
阿新 • • 發佈:2020-08-03
一:解題思路
二:完整程式碼示例 (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; }