Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. package v02;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.util.Scanner;
  5.  
  6. public class hw2 {
  7. private static int[][] data, holdOnes;
  8. private static int inLength, numIn, numOut;
  9. private static int[] ones;
  10. private static boolean[][] linked;
  11.  
  12. public static void main(String[] args) {
  13. runQM();
  14.  
  15. printData();
  16. }
  17.  
  18. private static void qmMethod() {
  19. for(int i = 0; i < numOut; i++) {
  20. get1s(i);
  21. reduceIt();
  22. checkUsed();
  23. }
  24. }
  25.  
  26. private static void checkUsed() {
  27. for(int i = 0; i < holdOnes.length; i++) {
  28. for(int j = i; j < holdOnes.length; j++) {
  29. if(linked[i][j]) {
  30.  
  31. }
  32. System.out.print(linked[i][j]+" ");
  33. }
  34. System.out.println();
  35. }
  36. }
  37.  
  38. private static void reduceIt() {
  39. for(int i = 0; i < holdOnes.length; i++) {
  40. for(int j = i; j < holdOnes.length; j++) {
  41. int counter = 0;
  42. for(int k = 0; k < numIn; k++) {
  43. if(holdOnes[i][k] != holdOnes[j][k]) {
  44. counter++;
  45. }
  46. }
  47. if(counter == 1) {
  48. linked[i][j] = true;
  49. System.out.println(i + "; " + j);
  50. }
  51. }
  52. }
  53. }
  54.  
  55. private static void get1s(int pos) {
  56. holdOnes = new int[ones[pos]][numIn];
  57. linked = new boolean[ones[pos]][ones[pos]];
  58. for(int i = 0; i < ones[pos]; i++) {
  59. for(int j = 0; j < ones[pos]; j++) {
  60. linked[i][j] = false;
  61. }
  62. }
  63. int counter = 0;
  64. for(int i = 0; i < inLength; i++) {
  65. if(data[numIn+pos][i] == 1) {
  66. for(int j = 0; j < numIn; j++) {
  67. holdOnes[counter][j] = data[j][i];
  68. }
  69. counter++;
  70. }
  71. }
  72. }
  73.  
  74. private static void runQM() {
  75. try {
  76. Scanner sc = new Scanner(new File("input.txt"));
  77. numIn = sc.nextInt();
  78. numOut = sc.nextInt();
  79. inLength = (int) Math.pow(2, numIn);
  80. data = new int[numIn+numOut][inLength];
  81. fillIn(numIn);
  82. fillOut(sc, numIn, numOut);
  83. qmMethod();
  84. sc.close();
  85. } catch (FileNotFoundException e) {
  86. System.out.println("Sorry, this file could not be found");
  87. }
  88. }
  89.  
  90. private static void fillOut(Scanner sc, int numIn, int numOut) {
  91. ones = new int[numOut];
  92. for(int i = 0; i < numOut; i++) {
  93. ones[i] = 0;
  94. }
  95. for(int j = 0; j < inLength; j++) {
  96. for(int i = numIn; i < (numIn+numOut); i++) {
  97. int num = sc.nextInt();
  98. if(num == 1) {
  99. ones[i-numIn]++;
  100. }
  101. data[i][j] = num;
  102. }
  103. }
  104. }
  105.  
  106. private static void fillIn(int numIn) {
  107. for(int i = 0; i < numIn; i++) {
  108. int fill = (int) (Math.pow(2, numIn)/Math.pow(2, i+1));
  109. boolean tf = true;
  110. for(int j = 0; j < inLength; j++) {
  111. if(j%fill == 0 && j > 0) {
  112. tf = !tf;
  113. }
  114. if(tf) {
  115. data[i][j] = 0;
  116. } else {
  117. data[i][j] = 1;
  118. }
  119. }
  120. }
  121. }
  122.  
  123. private static void printData() {
  124. for(int j = 0; j < inLength; j++) {
  125. for(int i = 0; i < data.length; i++) {
  126. System.out.print(data[i][j] + " ");
  127. }
  128. System.out.println();
  129. }
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement