Created
February 26, 2018 23:30
-
-
Save johirbuet/e8008f98c3baed9007e6dc4fa2c0101e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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