Skip to content

Instantly share code, notes, and snippets.

@johirbuet
Created February 26, 2018 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johirbuet/e8008f98c3baed9007e6dc4fa2c0101e to your computer and use it in GitHub Desktop.
Save johirbuet/e8008f98c3baed9007e6dc4fa2c0101e to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class UVA133 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()) {
int N = sc.nextInt();
int k =sc.nextInt();
int m = sc.nextInt();
if( N == 0 && m == 0 && k ==0 ) {
break;
}
int a = N - 1;
int b = 0;
boolean first =true;
boolean [] dead = new boolean[20];
int out = 0;
do {
for(int i =0; i < k ;i++) {
do {
a = (a + 1) % N;
} while (dead[a]);
}
for(int i =0; i<m;i++) {
do {
b = (b - 1 + N)%N;
} while(dead[b]);
}
if(!first) {
System.out.print(",");
} else {
first = false;
}
System.out.printf("%3d",a + 1);
dead[a] = true;
out++;
if(a != b) {
System.out.printf("%3d",b + 1);
dead[b] = true;
out++;
}
} while (out < N);
System.out.println();
}
sc.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment