#include <iostream> #include <map> #ifdef TEST_MODE #include <fstream> #endif using namespace std; int main() { #ifdef TEST_MODE std::ifstream in("1.in"); std::cin.rdbuf(in.rdbuf()); #endif std::ios_base::sync_with_stdio(false); string word; int n; cin >> n; cin >> word; int numberOf1 = 0; for ( int i = 0; i < word.length(); ++i ) { if ( word[i] == '1' ) numberOf1++; } if ( numberOf1 > 6 * n || numberOf1 < 3 * n ) { cout << "NIE" << endl; return 0; } map<int, char> letters{{3, 'a'},{4, 'c'},{5, 'g'},{6, 'o'}}; for ( int i = n - 1; i >= 0; --i ) { int max = i * 6; int l; for ( l = 3; l <= 6; ++l ) { if ( numberOf1 - l <= max ) { numberOf1 -= l; break; } } cout << letters[l]; } cout << endl; return 0; }
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 | #include <iostream> #include <map> #ifdef TEST_MODE #include <fstream> #endif using namespace std; int main() { #ifdef TEST_MODE std::ifstream in("1.in"); std::cin.rdbuf(in.rdbuf()); #endif std::ios_base::sync_with_stdio(false); string word; int n; cin >> n; cin >> word; int numberOf1 = 0; for ( int i = 0; i < word.length(); ++i ) { if ( word[i] == '1' ) numberOf1++; } if ( numberOf1 > 6 * n || numberOf1 < 3 * n ) { cout << "NIE" << endl; return 0; } map<int, char> letters{{3, 'a'},{4, 'c'},{5, 'g'},{6, 'o'}}; for ( int i = n - 1; i >= 0; --i ) { int max = i * 6; int l; for ( l = 3; l <= 6; ++l ) { if ( numberOf1 - l <= max ) { numberOf1 -= l; break; } } cout << letters[l]; } cout << endl; return 0; } |