#include<bits/stdc++.h> using namespace std; void common_operation(long long & ones, long long & zeros, string & result, int ones_v, int zeros_v, char result_v){ ones -= ones_v; zeros -= zeros_v; result += result_v; } int main(){ ios_base::sync_with_stdio(0); int n; cin >> n; string s; cin >> s; long long ones = 0, zeros = 0; for(int i=0; i<s.length(); i++){ if(s[i] == '1') ++ones; else ++zeros; } string result = ""; for(int i=0; i<n; i++){ long long diff = ones - zeros; long long integer_division = diff / (n-i); if(integer_division <= -2){ common_operation(ones, zeros, result, 3, 5, 'a'); } else if(integer_division < 2){ common_operation(ones, zeros, result, 4, 4, 'c'); } else if (integer_division < 4){ common_operation(ones, zeros, result, 5, 3, 'g'); } else { common_operation(ones, zeros, result, 6, 2, 'o'); } } if(ones == 0 && zeros == 0){ cout << result; } 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 | #include<bits/stdc++.h> using namespace std; void common_operation(long long & ones, long long & zeros, string & result, int ones_v, int zeros_v, char result_v){ ones -= ones_v; zeros -= zeros_v; result += result_v; } int main(){ ios_base::sync_with_stdio(0); int n; cin >> n; string s; cin >> s; long long ones = 0, zeros = 0; for(int i=0; i<s.length(); i++){ if(s[i] == '1') ++ones; else ++zeros; } string result = ""; for(int i=0; i<n; i++){ long long diff = ones - zeros; long long integer_division = diff / (n-i); if(integer_division <= -2){ common_operation(ones, zeros, result, 3, 5, 'a'); } else if(integer_division < 2){ common_operation(ones, zeros, result, 4, 4, 'c'); } else if (integer_division < 4){ common_operation(ones, zeros, result, 5, 3, 'g'); } else { common_operation(ones, zeros, result, 6, 2, 'o'); } } if(ones == 0 && zeros == 0){ cout << result; } else{ cout << "NIE"; } } |