#include <bits/stdc++.h>
using namespace std;
int x, n;
char tab[10];
int count (string s)
{
int l=0;
for (int i=0; i<s.size(); i++)
if (s[i] == '1') l++;
return l;
}
void write (int a, int b)
{
int l1 = x - (a * n);
int l2 = n - l1;
for (int i=0; i<l2; i++)
cout<<tab[a];
for (int i=0; i<l1; i++)
cout<<tab[b];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
tab[3] = 'a', tab[4] = 'c', tab[5] = 'g', tab[6] = 'o';
string s;
cin>>n>>s;
x = count(s);
if (x < n*3 || x > n*6)
{
cout<<"NIE";
return 0;
}
if (n * 4 >= x)
{
write (3, 4);
return 0;
}
if (n * 5 >= x)
{
write (4, 5);
return 0;
}
if (n * 6 >= x)
{
write (5, 6);
return 0;
}
cout<<"NIE";
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 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <bits/stdc++.h> using namespace std; int x, n; char tab[10]; int count (string s) { int l=0; for (int i=0; i<s.size(); i++) if (s[i] == '1') l++; return l; } void write (int a, int b) { int l1 = x - (a * n); int l2 = n - l1; for (int i=0; i<l2; i++) cout<<tab[a]; for (int i=0; i<l1; i++) cout<<tab[b]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); tab[3] = 'a', tab[4] = 'c', tab[5] = 'g', tab[6] = 'o'; string s; cin>>n>>s; x = count(s); if (x < n*3 || x > n*6) { cout<<"NIE"; return 0; } if (n * 4 >= x) { write (3, 4); return 0; } if (n * 5 >= x) { write (4, 5); return 0; } if (n * 6 >= x) { write (5, 6); return 0; } cout<<"NIE"; return 0; } |
English