View Code of Problem 3309

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in =new Scanner(System.in);
		int n =in.nextInt();
		ArrayList<String> name = new ArrayList<String>();
		for(int i =0;i<n;i++) {
			name.add(in.next());
		}
		String[] ws = in.next().split(",");
		int w =Integer.parseInt(ws[0]);
		int s =Integer.parseInt(ws[1]);
		int count=1;
		int len=n;
		int loc=w-1;
		while(name.size()>=s) {		
			if(count==s) {
				System.out.println(name.get(loc));
				name.remove(loc);
				loc--;
				count=0;
			}
			count++;
			loc++;
			if(loc==name.size()) {
				loc=0;
			}
		}
		count=1;
		while(name.size()>0) {
			if(count==s) {
				System.out.println(name.get(loc));
				name.remove(loc);
				loc--;
			}
			count++;
			if(count==s+1) {
				count=1;
			}
			loc++;
			if(loc==name.size()) {
				loc=0;
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 3309