华为-MP3光标位置
题目链接
输入歌曲数量2 输入命令 U或者D
输出描述:
输出说明1 输出当前列表2 输出当前选中歌曲
示例1
输入
复制
10UUUU
输出
复制
7 8 9 107
题解:
#include #include using namespace std;int main(){ int n; string s; while (cin >> n >> s){ int point = 1; int now = 1; if (n <= 3){ for (int i = 1; i < n; i++){ cout << i << " "; } cout << n << endl; for (int i = 0; i < s.length(); i++){ if (s[i] == 'U'){ if (point == 1){ point = n; } else{ point--; } } else if (s[i] == 'D'){ if (point == n){ point = 1; } else{ point++; } } } cout << point << endl; } else{ for (int i = 0; i < s.length(); i++){ if (s[i] == 'U'){ if (point == 1){ point = n; now = 4; } else{ if (now != 1){ point--; now--; } else{ point--; } } } else if (s[i] == 'D'){ if (point == n){ point = 1; now = 1; } else{ if (now != 4){ point++; now++; } else{ point++; } } } } switch (now){ case 1:cout << point << " " << point + 1 << " " << point + 2 << " " << point + 3 << endl << point << endl;break; case 2:cout << point - 1 << " " << point << " " << point + 1 << " " << point + 2 << endl << point << endl;break; case 3:cout << point - 2 << " " << point - 1 << " " << point << " " << point + 1 << endl << point << endl;break; case 4:cout << point - 3 << " " << point - 2 << " " << point - 1 << " " << point << endl << point << endl;break; } } } return 0;}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~