#include <array> #include <iostream> using namespace std; const int MAXN = 100000 + 7; const int MAXZERO = 5; const int MINZERO = 2; const int MAXJEDEN = 6; const int MINJEDEN = 3; struct Data { int ile0 = -1, ile1 = -1; Data(int i, int j) { ile1 = i; ile0 = j; } Data(){} }; // first -> ile jedynek // second -> ile zer array<Data, MAXN>tab; char dataToChar(Data* d) { switch (d->ile1) { case 3: return 'a'; case 4: return 'c'; case 5: return 'g'; default: return 'o'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // i -> ile jedynek // j -> ile zer int i = 0, j = 0; int n; cin>>n; string s; cin>>s; for(char c : s) c == '1' ? i++ : j++; if(j > n * MAXZERO || j < n * MINZERO || i < n * MINJEDEN || i > n * MAXJEDEN) { cout<<"NIE\n"; return 0; } tab.fill({MINJEDEN, MINZERO}); i -= n * MINJEDEN; j -= n * MINZERO; int y = 0; for(int x = 0; x < i; x++) { tab[y].ile1++; y = (y + 1) % n; } for(int x = 0; x < j; x++) { tab[y].ile0++; y = (y + 1) % n; } string out = ""; for(int i = 0; i < n; i++) { out += dataToChar(&tab[i]); } cout<<out<<'\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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #include <array> #include <iostream> using namespace std; const int MAXN = 100000 + 7; const int MAXZERO = 5; const int MINZERO = 2; const int MAXJEDEN = 6; const int MINJEDEN = 3; struct Data { int ile0 = -1, ile1 = -1; Data(int i, int j) { ile1 = i; ile0 = j; } Data(){} }; // first -> ile jedynek // second -> ile zer array<Data, MAXN>tab; char dataToChar(Data* d) { switch (d->ile1) { case 3: return 'a'; case 4: return 'c'; case 5: return 'g'; default: return 'o'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // i -> ile jedynek // j -> ile zer int i = 0, j = 0; int n; cin>>n; string s; cin>>s; for(char c : s) c == '1' ? i++ : j++; if(j > n * MAXZERO || j < n * MINZERO || i < n * MINJEDEN || i > n * MAXJEDEN) { cout<<"NIE\n"; return 0; } tab.fill({MINJEDEN, MINZERO}); i -= n * MINJEDEN; j -= n * MINZERO; int y = 0; for(int x = 0; x < i; x++) { tab[y].ile1++; y = (y + 1) % n; } for(int x = 0; x < j; x++) { tab[y].ile0++; y = (y + 1) % n; } string out = ""; for(int i = 0; i < n; i++) { out += dataToChar(&tab[i]); } cout<<out<<'\n'; return 0; } |