#include<iostream> #include<vector> #include<algorithm> using namespace std; #define MAXN 100000 #define MAX_BITS 800000 int main() { int n; vector<int> v; cin >> n; int bits = n * 8; int one_count = 0; for (int i = 0; i < bits; i++) { char v; cin >> v; if (v == '1') one_count++; } // cout << one_count << endl; if (one_count > n * 6 || one_count < n * 3) { cout << "NIE" << endl; } else if (one_count > n * 4) { // Trzeba dodawać więcej X for (int i = 0; i < n; ++i) { // << "ITERATION " << i << "; one_count=" << one_count << endl; int chars_left = n - i; if (one_count == chars_left * 4) { cout << 'c'; one_count -= 4; } else if (one_count - 1 == chars_left * 4) { cout << 'g'; one_count -= 5; } else { cout << 'o'; one_count -= 6; } } //cout << endl; } else { // one_count >= n * 4 - trzeba dodawać więcej X for (int i = 0; i < n; ++i) { //cout << "ITERATION " << i << "; one_count=" << one_count << endl; int chars_left = n - i; if (one_count == chars_left * 4) { cout << 'c'; one_count -= 4; } else { cout << 'a'; one_count -= 3; } } //cout << endl; } }
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 | #include<iostream> #include<vector> #include<algorithm> using namespace std; #define MAXN 100000 #define MAX_BITS 800000 int main() { int n; vector<int> v; cin >> n; int bits = n * 8; int one_count = 0; for (int i = 0; i < bits; i++) { char v; cin >> v; if (v == '1') one_count++; } // cout << one_count << endl; if (one_count > n * 6 || one_count < n * 3) { cout << "NIE" << endl; } else if (one_count > n * 4) { // Trzeba dodawać więcej X for (int i = 0; i < n; ++i) { // << "ITERATION " << i << "; one_count=" << one_count << endl; int chars_left = n - i; if (one_count == chars_left * 4) { cout << 'c'; one_count -= 4; } else if (one_count - 1 == chars_left * 4) { cout << 'g'; one_count -= 5; } else { cout << 'o'; one_count -= 6; } } //cout << endl; } else { // one_count >= n * 4 - trzeba dodawać więcej X for (int i = 0; i < n; ++i) { //cout << "ITERATION " << i << "; one_count=" << one_count << endl; int chars_left = n - i; if (one_count == chars_left * 4) { cout << 'c'; one_count -= 4; } else { cout << 'a'; one_count -= 3; } } //cout << endl; } } |