Guest User

Untitled

a guest
Apr 26th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.*;
  3.  
  4. public class Critical {
  5. public static void main(String[] args) {
  6. Scanner scan = new Scanner(System.in);
  7. String input = scan.nextLine();
  8. LinkedHashMap<String, ArrayList<BigInteger>> lista = new LinkedHashMap<>();
  9. ArrayList<BigInteger> num = new ArrayList<>();
  10. String counter = "0";
  11. BigInteger rows = BigInteger.valueOf(0);
  12. int ROWS = 0;
  13. while (!input.equals("Break it.")) {
  14. String[] numbers = input.split(" ");
  15.  
  16. BigInteger one = BigInteger.valueOf(Integer.parseInt(numbers[0]));
  17. BigInteger two = BigInteger.valueOf(Integer.parseInt(numbers[1]));
  18. BigInteger three = BigInteger.valueOf(Integer.parseInt(numbers[2]));
  19. BigInteger four = BigInteger.valueOf(Integer.parseInt(numbers[3]));
  20.  
  21. lista.put(counter, new ArrayList<>());
  22. lista.get(counter).add(one);
  23. lista.get(counter).add(two);
  24. lista.get(counter).add(three);
  25. lista.get(counter).add(four);
  26.  
  27. BigInteger criticRatio =((four.add(three)).subtract(two.add(one))).abs();
  28. num.add(criticRatio);
  29.  
  30. counter = (counter) + (1);
  31. rows=rows.add(BigInteger.ONE);
  32. ROWS++;
  33. input = scan.nextLine();
  34. }
  35. Collections.sort(num);
  36. boolean isEqual = false;
  37.  
  38. BigInteger total = BigInteger.valueOf(0);
  39.  
  40. for (int i = 0; i < num.size(); i++) {
  41.  
  42. total = total.add(num.get(i));
  43. }
  44. BigInteger sized = new BigInteger(Integer.toString(num.size()));//obrushta razmera na arreya v bigint
  45. BigInteger average = total.divide(sized);//smqta srednata stoinost
  46.  
  47.  
  48. if (num.contains(BigInteger.ZERO)) {//ako ima nuli!!!!!!!!!!!!!!!!!!!prepravi go
  49. if (total == BigInteger.ZERO) {//ako ima samo nuli
  50. for (String s : lista.keySet()) {
  51. int countPossition = 1;
  52. System.out.print("Line: [");
  53. ArrayList<BigInteger> spisuk = lista.get(s);
  54. for (BigInteger integer : spisuk) {
  55. if (countPossition == 4) {
  56. System.out.print(integer + "]");
  57. } else {
  58. System.out.print(integer + ", ");
  59. }
  60. countPossition++;
  61. }
  62. System.out.println();
  63. }
  64. System.out.printf("Critical Breakpoint: 0");
  65. System.out.println();
  66. } else {
  67.  
  68. while (num.get(0) == BigInteger.ZERO) {
  69. num.remove(0);
  70. }
  71.  
  72. for (int i = 0; i < num.size(); i++) {
  73. for (int j = 1; j < num.size(); j++) {
  74.  
  75. if (num.get(i).compareTo(num.get(j))!=0) {////ako ostanalite chisla bez nulite sa razlichni*******tova ne sravnqva pravilno
  76. isEqual = false;
  77. System.out.println("Critical breakpoint does not exist.");
  78. break;
  79.  
  80. } else {
  81. isEqual = true;
  82. }
  83. }
  84. }
  85.  
  86. if (isEqual = true) {//ima nuli i ednakvi dr chisla
  87. BigInteger br = (num.get(0).pow(ROWS)).mod(rows); //smqta kritichnata tocka na purviq element/dr sa sushtite chisla kato purvoto
  88. for (String s : lista.keySet()) {
  89. int countPossition = 1;
  90. System.out.print("Line: [");
  91. ArrayList<BigInteger> spisuk = lista.get(s);
  92. for (BigInteger integer : spisuk) {
  93. if (countPossition == 4) {
  94. System.out.print(integer + "]");
  95. } else {
  96. System.out.print(integer + ", ");
  97. }
  98. countPossition++;
  99. }
  100. System.out.println();
  101. }
  102. System.out.printf("Critical Breakpoint: %d", br);
  103. System.out.println();
  104. }
  105. }
  106.  
  107.  
  108. } else {//kogato ima samo razl ot nula chisla
  109. for (int i = 0; i < num.size() - 1; i++) {
  110. for (int j = 1; j < num.size(); j++) {
  111. if (num.get(i).compareTo(num.get(j))!=0) {////ako sa razlichni
  112. isEqual = false;
  113. System.out.println("Critical breakpoint does not exist.");
  114. return;
  115. } else {
  116. isEqual = true;
  117. }
  118. }
  119. }
  120. if (isEqual = true) {
  121. BigInteger br = (num.get(0).pow(ROWS)).mod(rows); //smqta kritichnata tocka na purviq element/dr sa sushtite chisla kato purvoto
  122. for (String s : lista.keySet()) {
  123. int countPossition = 1;
  124. System.out.print("Line: [");
  125. ArrayList<BigInteger> spisuk = lista.get(s);
  126. for (BigInteger integer : spisuk) {
  127. if (countPossition == 4) {
  128. System.out.print(integer + "]");
  129. } else {
  130. System.out.print(integer + ", ");
  131. }
  132. countPossition++;
  133. }
  134. System.out.println();
  135. }
  136. System.out.printf("Critical Breakpoint: %d", br);
  137. System.out.println();
  138. }
  139.  
  140. }
  141.  
  142.  
  143. }
  144.  
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment