View Code of Problem 3309

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String[] names = new String[n];
        for (int i = 0; i < names.length; i++) {
            names[i] = scanner.next();
        }
        String[] input = scanner.next().split(",");
        int start = Integer.valueOf(input[0]);
        int count = Integer.valueOf(input[1]);
        int num = 0;
        for (int i = start-1; i < names.length; i++) {
            if(!names[i].equals("") && ++num == count){
                System.out.println(names[i]);
                names[i] = "";
                num = 0;
            }
            if (i == names.length-1){
                i = -1;
            }
            boolean flag = true;
            for (int j = 0; j < names.length; j++) {
                if (!names[j].equals("")){
                    flag = false;
                }
            }
            if (flag)break;
        }

    }
}

Double click to view unformatted code.


Back to problem 3309