#include <bits/stdc++.h>
using namespace std;
using ll = long long;
pair<int, char> res[4] = {{0,'a'}, {0,'c'}, {0,'g'}, {0,'o'}};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
char tmp;
cin >> n;
int cnt = 0;
for(int i = 0; i < 8*n; i++) {
cin >> tmp;
cnt += (tmp == '1' ? 1 : 0);
}
if(cnt < 3*n or 6*n < cnt)
cout << "NIE\n";
else {
cnt -= 3*n;
res[3].first = cnt / 3;
cnt %= 3;
res[2].first = cnt / 2;
cnt %= 2;
res[1].first = cnt;
res[0].first = n - res[1].first - res[2].first - res[3].first;
for(int i = 0; i < 4; i++) {
for(int j = 0; j < res[i].first; j++)
cout << res[i].second;
}
cout << "\n";
}
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 | #include <bits/stdc++.h> using namespace std; using ll = long long; pair<int, char> res[4] = {{0,'a'}, {0,'c'}, {0,'g'}, {0,'o'}}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; char tmp; cin >> n; int cnt = 0; for(int i = 0; i < 8*n; i++) { cin >> tmp; cnt += (tmp == '1' ? 1 : 0); } if(cnt < 3*n or 6*n < cnt) cout << "NIE\n"; else { cnt -= 3*n; res[3].first = cnt / 3; cnt %= 3; res[2].first = cnt / 2; cnt %= 2; res[1].first = cnt; res[0].first = n - res[1].first - res[2].first - res[3].first; for(int i = 0; i < 4; i++) { for(int j = 0; j < res[i].first; j++) cout << res[i].second; } cout << "\n"; } return 0; } |
English