uva133 java

·  阅读 38

import java.io.InputStream; import java.util.*;

public class Main {

interface Printer {
    void p(Object o);
}

public static void main(String[] args) {
    solution(System.in, it -> System.out.print(it.toString()));
}


public static void solution(InputStream in, Printer p) {
    Scanner scanner = new Scanner(in);
    while (true) {
        int length = scanner.nextInt();
        int step1 = scanner.nextInt();
        int step2 = scanner.nextInt();
        if (length == 0 && step1 == 0 && step2 == 0) {
            break;
        }
        scanner.nextLine();
        int[] people = new int[length];
        int size = length;
        for (int i = 0;i < length;i++) {
            people[i] = i+1;
        }
        StringBuffer sb = new StringBuffer();
        int currentA = length - 1, currentB = 0;
        while (size > 0) {
            int step = step1;
            while (step > 0) {
                currentA = (currentA + 1) % length;
                if (people[currentA] > 0) {
                    step--;
                }
            }

            step = step2;
            while (step > 0) {
                currentB = (currentB - 1 + length) % length;
                if (people[currentB] > 0) {
                    step--;
                }
            }
            sb.append(String.format("%3d", people[currentA]));
            people[currentA] = 0;
            size --;
            if (people[currentB] > 0) {
                sb.append(String.format("%3d", people[currentB]));
                people[currentB] = 0;
                size --;
            }
            sb.append(size == 0 ? "\n" : ",");
        }
        p.p(sb.toString());
    }
}

}

分类:
后端
标签:
分类:
后端
标签:
收藏成功!
已添加到「」, 点击更改