Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 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.  
  11. public static void main(String[] args) {
  12. runQM();
  13.  
  14. printData();
  15. }
  16.  
  17. private static void qmMethod() {
  18. for(int i = 0; i < numOut; i++) {
  19. get1s(i);
  20. groupBy1();
  21. }
  22. }
  23.  
  24. private static void groupBy1() {
  25.  
  26. }
  27.  
  28. private static void get1s(int pos) {
  29. holdOnes = new int[ones[pos]][numIn];
  30. int counter = 0;
  31. for(int i = 0; i < inLength; i++) {
  32. if(data[numIn+pos][i] == 1) {
  33. for(int j = 0; j < numIn; j++) {
  34. holdOnes[counter][j] = data[j][i];
  35. System.out.print(holdOnes[counter][j] + " ");
  36. }
  37. System.out.println();
  38. counter++;
  39. }
  40. }
  41. }
  42.  
  43. private static void runQM() {
  44. try {
  45. Scanner sc = new Scanner(new File("input.txt"));
  46. numIn = sc.nextInt();
  47. numOut = sc.nextInt();
  48. inLength = (int) Math.pow(2, numIn);
  49. data = new int[numIn+numOut][inLength];
  50. fillIn(numIn);
  51. fillOut(sc, numIn, numOut);
  52. qmMethod();
  53. sc.close();
  54. } catch (FileNotFoundException e) {
  55. System.out.println("Sorry, this file could not be found");
  56. }
  57. }
  58.  
  59. private static void fillOut(Scanner sc, int numIn, int numOut) {
  60. ones = new int[numOut];
  61. for(int i = 0; i < numOut; i++) {
  62. ones[i] = 0;
  63. }
  64. for(int j = 0; j < inLength; j++) {
  65. for(int i = numIn; i < (numIn+numOut); i++) {
  66. int num = sc.nextInt();
  67. if(num == 1) {
  68. ones[i-numIn]++;
  69. }
  70. data[i][j] = num;
  71. }
  72. }
  73. }
  74.  
  75. private static void fillIn(int numIn) {
  76. for(int i = 0; i < numIn; i++) {
  77. int fill = (int) (Math.pow(2, numIn)/Math.pow(2, i+1));
  78. boolean tf = true;
  79. for(int j = 0; j < inLength; j++) {
  80. if(j%fill == 0 && j > 0) {
  81. tf = !tf;
  82. }
  83. if(tf) {
  84. data[i][j] = 0;
  85. } else {
  86. data[i][j] = 1;
  87. }
  88. }
  89. }
  90. }
  91.  
  92. private static void printData() {
  93. for(int j = 0; j < inLength; j++) {
  94. for(int i = 0; i < data.length; i++) {
  95. System.out.print(data[i][j] + " ");
  96. }
  97. System.out.println();
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement