题解 | #MP3光标位置#
MP3光标位置
https://www.nowcoder.com/practice/eaf5b886bd6645dd9cfb5406f3753e15
package com.huawei; import java.util.*; public class guangbiao { public static void main(String[] args) { Scanner input = new Scanner(System.in); int nums = input.nextInt(); input.nextLine(); String op = input.nextLine(); int low = 1, high = 4; int now = 1; if(nums <= 4){ low = 1; high = nums; for(char opp : op.toCharArray()){ if(opp == 'U'){ now--; if(now == low - 1){ now = high; } }else{ now++; if(now == high + 1){ now = low; } } } }else{ for(char opp : op.toCharArray()){ if(opp == 'U'){ now--; if(now == 0){ now = nums; low = nums - 3; high = nums; } else if(now == low - 1){ low--; high--; } }else{ now++; if(now == nums + 1){ now = 1; low = now; high = now + 3; }else if(now == high + 1){ high++; low++; } } } } for (int i = low; i <= high; i++) { System.out.print(i + " "); } System.out.println(); System.out.println(now); } }
#华为笔试#