//Mateusz Piórkowski #include <iostream> #include <string> #include <algorithm> const char characters[] = {'a','c','g','o'}; int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; std::string msg; std::cin >> msg; int onecount=0; for(char i : msg){ if(i=='1') onecount++; } //std::cout << onecount << "\n"; int min_ones = n*3; int max_ones = n*6; if((onecount<min_ones) || (onecount>max_ones)){ std::cout << "NIE\n"; return 0; } int ones_to_add = onecount-min_ones; int chars_printed = 0; //std::cout << "Need to add " << ones_to_add << " ones\n"; while(ones_to_add>0){ int current_to_add = std::min(ones_to_add,3); //std::cout << "Adding " << current_to_add << "\n"; ones_to_add-=current_to_add; std::cout << characters[current_to_add]; chars_printed++; } for(int i=0; i<(n-chars_printed); i++){ std::cout << 'a'; } std::cout << "\n"; }
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 | //Mateusz Piórkowski #include <iostream> #include <string> #include <algorithm> const char characters[] = {'a','c','g','o'}; int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; std::string msg; std::cin >> msg; int onecount=0; for(char i : msg){ if(i=='1') onecount++; } //std::cout << onecount << "\n"; int min_ones = n*3; int max_ones = n*6; if((onecount<min_ones) || (onecount>max_ones)){ std::cout << "NIE\n"; return 0; } int ones_to_add = onecount-min_ones; int chars_printed = 0; //std::cout << "Need to add " << ones_to_add << " ones\n"; while(ones_to_add>0){ int current_to_add = std::min(ones_to_add,3); //std::cout << "Adding " << current_to_add << "\n"; ones_to_add-=current_to_add; std::cout << characters[current_to_add]; chars_printed++; } for(int i=0; i<(n-chars_printed); i++){ std::cout << 'a'; } std::cout << "\n"; } |