#include <iostream> using namespace std; bool check(string &s, int zeroes, int ones) { int c0, c1; for (string::size_type i = 0; i < s.size(); i++) { if (s[i] == 'a') { c0 += 5; c1 += 3; } else if (s[i] == 'c') { c0 += 4; c1 += 4; } else if (s[i] == 'g') { c0 += 3; c1 += 5; } else if (s[i] == 'w') { c0 += 2; c1 += 6; } } return (c0 == zeroes && c1 == ones); } int main() { int n; cin >> n; int zeroes = 0, ones = 0; int a = 0, c = 0, g = 0, w = 0; for (int i = 0; i < 8*n; i++) { char byte; cin >> byte; if (byte == '0') { zeroes++; } else { ones++; } } int zeroes_input = zeroes; int ones_input = ones; for (int i = 0; i < n; i++) { if (zeroes > ones) { a++; zeroes -= 5; ones -= 3; } else if (zeroes == ones) { c++; zeroes -= 4; ones -= 4; } else if (zeroes + 1 == ones || zeroes + 2 == ones) { g++; zeroes -= 3; ones -= 5; } else { w++; zeroes -= 2; ones -= 6; } } if (zeroes == 0 && ones == 0) { string word = string(a, 'a') + string(c, 'c') + string(g, 'g') + string(w, 'w'); // bool correct = check(word, zeroes_input, ones_input); // cout << correct << endl; cout << word << endl; // cout << "TAK"; } else { cout << "NIE"; } }
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 | #include <iostream> using namespace std; bool check(string &s, int zeroes, int ones) { int c0, c1; for (string::size_type i = 0; i < s.size(); i++) { if (s[i] == 'a') { c0 += 5; c1 += 3; } else if (s[i] == 'c') { c0 += 4; c1 += 4; } else if (s[i] == 'g') { c0 += 3; c1 += 5; } else if (s[i] == 'w') { c0 += 2; c1 += 6; } } return (c0 == zeroes && c1 == ones); } int main() { int n; cin >> n; int zeroes = 0, ones = 0; int a = 0, c = 0, g = 0, w = 0; for (int i = 0; i < 8*n; i++) { char byte; cin >> byte; if (byte == '0') { zeroes++; } else { ones++; } } int zeroes_input = zeroes; int ones_input = ones; for (int i = 0; i < n; i++) { if (zeroes > ones) { a++; zeroes -= 5; ones -= 3; } else if (zeroes == ones) { c++; zeroes -= 4; ones -= 4; } else if (zeroes + 1 == ones || zeroes + 2 == ones) { g++; zeroes -= 3; ones -= 5; } else { w++; zeroes -= 2; ones -= 6; } } if (zeroes == 0 && ones == 0) { string word = string(a, 'a') + string(c, 'c') + string(g, 'g') + string(w, 'w'); // bool correct = check(word, zeroes_input, ones_input); // cout << correct << endl; cout << word << endl; // cout << "TAK"; } else { cout << "NIE"; } } |