Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class TheRingOfFire {
  5. public static void main(String[] args) {
  6.  
  7. Scanner console = new Scanner(args[0]);
  8. //Scanner console = new Scanner(System.in);
  9. int length = console.nextInt();
  10. int threshold = console.nextInt();
  11. int studentsLeft = console.nextInt();
  12.  
  13. ArrayList<Integer> ArrayList = new ArrayList<>();
  14. for (int i = 1; i < length+1; i++) {
  15. ArrayList.add(i);
  16. }
  17.  
  18. console.close();
  19.  
  20. //ArrayList = RingOfFire(ArrayList, threshold, studentsLeft);
  21. ArrayList = removeN(ArrayList, threshold, studentsLeft);
  22. System.out.print(ArrayList.toString());
  23. }
  24.  
  25. /*private static ArrayList<Integer> RingOfFire(ArrayList<Integer> IntegerArray, int threshold, int studentsLeft) {
  26. int counter = 0;
  27. int size = IntegerArray.size();
  28. for(int i = 0; i < size - studentsLeft; i++){
  29. counter += threshold;
  30. if(counter >= IntegerArray.size()){
  31. int round = (int)Math.floor(counter+threshold/size);
  32. counter = counter-round;
  33. }
  34. IntegerArray.remove(counter-i);
  35. counter = 0;
  36. }
  37. return IntegerArray;
  38. }
  39. */
  40.  
  41. private static ArrayList<Integer> removeN(ArrayList<Integer> arr, int threshold, int nrOfStudents) {
  42. int cCounter = 1;
  43. int iCounter = 0;
  44. while (arr.size() > nrOfStudents) {
  45. if (iCounter >= arr.size()) {
  46. //iCounter = Math.abs(iCounter - arr.size());
  47. iCounter = iCounter % arr.size();
  48.  
  49. }
  50. if (cCounter != threshold) {
  51. cCounter++;
  52. iCounter++;
  53. } else {
  54. cCounter = 1;
  55. arr.remove(iCounter);
  56. }
  57. }
  58. return arr;
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement