Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package v02;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class hw2 {
- private static int[][] data, holdOnes;
- private static int inLength, numIn, numOut;
- private static int[] ones;
- public static void main(String[] args) {
- runQM();
- printData();
- }
- private static void qmMethod() {
- for(int i = 0; i < numOut; i++) {
- get1s(i);
- groupBy1();
- }
- }
- private static void groupBy1() {
- }
- private static void get1s(int pos) {
- holdOnes = new int[ones[pos]][numIn];
- int counter = 0;
- for(int i = 0; i < inLength; i++) {
- if(data[numIn+pos][i] == 1) {
- for(int j = 0; j < numIn; j++) {
- holdOnes[counter][j] = data[j][i];
- System.out.print(holdOnes[counter][j] + " ");
- }
- System.out.println();
- counter++;
- }
- }
- }
- private static void runQM() {
- try {
- Scanner sc = new Scanner(new File("input.txt"));
- numIn = sc.nextInt();
- numOut = sc.nextInt();
- inLength = (int) Math.pow(2, numIn);
- data = new int[numIn+numOut][inLength];
- fillIn(numIn);
- fillOut(sc, numIn, numOut);
- qmMethod();
- sc.close();
- } catch (FileNotFoundException e) {
- System.out.println("Sorry, this file could not be found");
- }
- }
- private static void fillOut(Scanner sc, int numIn, int numOut) {
- ones = new int[numOut];
- for(int i = 0; i < numOut; i++) {
- ones[i] = 0;
- }
- for(int j = 0; j < inLength; j++) {
- for(int i = numIn; i < (numIn+numOut); i++) {
- int num = sc.nextInt();
- if(num == 1) {
- ones[i-numIn]++;
- }
- data[i][j] = num;
- }
- }
- }
- private static void fillIn(int numIn) {
- for(int i = 0; i < numIn; i++) {
- int fill = (int) (Math.pow(2, numIn)/Math.pow(2, i+1));
- boolean tf = true;
- for(int j = 0; j < inLength; j++) {
- if(j%fill == 0 && j > 0) {
- tf = !tf;
- }
- if(tf) {
- data[i][j] = 0;
- } else {
- data[i][j] = 1;
- }
- }
- }
- }
- private static void printData() {
- for(int j = 0; j < inLength; j++) {
- for(int i = 0; i < data.length; i++) {
- System.out.print(data[i][j] + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement