Код Хемминга

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

import java.util.*;
import java.io.*;

public class Main {
    // 1 2 3 4 5
    // 1 4 3 2 5
    // 1 3 2 4 5
    // 1 3 4 2 5
    private void solve() throws IOException {
        int[] a = new int[7];
        for (int i = 0; i < 7; i++) {
            a[i] = in.nextInt();
        }
        int[] b;
        int sum1 = a[1] + a[2] + a[3];
        int sum2 = a[0] + a[2] + a[3];
        int sum3 = a[0] + a[1] + a[3];
        if (sum1 % 2 == a[4] && sum2 % 2 == a[5] && sum3 % 2 == a[6]) {
            System.out.println(a[0] + " " + a[1] + " " + a[2] + " " + a[3] + " " + a[4] + " " + a[5] + " " + a[6]);
            return;
        }
        for (int i = 0; i < 7; i++) {
            b = a.clone();
            b[i] = -1 * (b[i] - 1);
            int s1 = b[1] + b[2] + b[3];
            int s2 = b[0] + b[2] + b[3];
            int s3 = b[0] + b[1] + b[3];
            if (s1 % 2 == b[4] && s2 % 2 == b[5] && s3 % 2 == b[6]) {
                System.out.println(b[0] + " " + b[1] + " " + b[2] + " " + b[3] + " " + b[4] + " " + b[5] + " " + b[6]);
                return;
            }
        }
}

    private String filename = "";
    private PrintWriter out;
    MyScanner in;

    private void run() throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    private class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() throws IOException {
            this.br = new BufferedReader(new InputStreamReader(System.in));
        }

        public MyScanner(String fileTitle) throws IOException {
            this.br = new BufferedReader(new FileReader(fileTitle));
        }

        public String nextLine() throws IOException {
            String s = br.readLine();
            return s == null ? "-1" : s;
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return "-1";
                }
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.parseInt(this.next());
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(this.next());
        }

        public Double nextDouble() throws IOException {
            return Double.parseDouble(this.next());
        }

        public void close() throws IOException {
            this.br.close();
        }
    }

    public static void main(String[] args) throws IOException{
        Locale.setDefault(Locale.US);
        new Main().run();
    }
}