andy6804tw
7/16/2016 - 10:10 AM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=25163 這題就以模擬方式下去做判斷,利用迴圈假如成立就1直到最後只有1個0

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=25163 這題就以模擬方式下去做判斷,利用迴圈假如成立就1直到最後只有1個0

import java.util.*;
 
public class Main {
 
 public static void main(String[] args) {
  Scanner scn = new Scanner(System.in);
  int n = scn.nextInt();
  while (n-- != 0) {
   int a = scn.nextInt(), b = scn.nextInt(), arr[] = new int[a], count = 0, i = 0, j = 0;
   while (true) {
    if (j >= a)
     j = 0;
    if (arr[j] == 0)
     i++;
    if (i == b) {
     arr[j] = 1;
     i = 0;
     count++;
    }
    if (count == a - 1)
     break;
    j++;
   }
   for (i = 0; i < a; i++)
    if (arr[i] == 0)
     break;
   System.out.println(i + 1);
 
  }
 }
 /* 
    題目:[Problem 2] 心得報數
    作者:1010
    時間:西元 2016 年 7 月 */
}