fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) {
  11. try(Scanner s = new Scanner(System.in))
  12. {
  13. int n = s.nextInt();
  14. int d = s.nextInt();
  15. int k = s.nextInt();
  16. int j = s.nextInt();
  17.  
  18. //여기부터 작성해 주세요
  19. System.out.println(winner(n,d,k,j));
  20. }
  21. }
  22.  
  23. public static int winner(int n, int d, int k, int j) {
  24. ArrayList<Integer> people = new ArrayList();
  25. int pos = k;
  26.  
  27. for(int i=1;i<=n;i++)
  28. people.add(i);
  29.  
  30. people.remove(pos);
  31. while(people.size() != 1) {
  32. pos = (pos + j) % people.size();
  33. people.remove(pos);
  34. }
  35. return people.get(0);
  36. }
  37. }
  38.  
Runtime error #stdin #stdout #stderr 0.06s 4386816KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1485)
	at java.util.Scanner.nextInt(Scanner.java:2117)
	at java.util.Scanner.nextInt(Scanner.java:2076)
	at Ideone.main(Main.java:13)