#include <bits/stdc++.h>
using namespace std;
int n,sr;
vector<int> v;
string s;
bool zakoncz;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i = 0; i < n; i++){
int jed = 0, zer = 0;
for(int j = 0; j < 8; j++){
char x;
cin>>x;
if(x == '1') jed++;
else zer++;
}
v.push_back(jed);
sr+=jed;
}
// for(int i = 0; i < n; i++) cout<<"w "<<i+1<<" literce jest "<<v[i]<<" jedynek"<<endl;
sr/=n;
if(sr < 3 || sr > 6){
cout<<"NIE"<<"\n";
return 0;
}
sort(v.begin(),v.end());
int pula = 0;
for(int i = 0; i < n; i++){
if(v[i] > sr) pula+=v[i]-sr, v[i] = sr;
}
int i = 0;
while(v[i] < sr){
// cerr<<"SREDNIA = "<<sr<<endl;
// cerr<<"w literce "<<i<<" jest ponizej sredniej wiec dodaje tam "<<abs(sr-v[i])<<endl;
pula-= abs(sr-v[i]);
v[i] = sr;
i++;
}
i = 0;
while(pula > 0){
i = 0;
// cerr<<"pula ciagle jest > 0 wiec rozdaje reszte"<<endl;
while(pula > 0 && i < n) v[i]++, pula--, i++;
}
for(int i = 0; i < n; i++){
if(v[i] > 6) zakoncz = true;
if(v[i] == 3) s = s+'a';
if(v[i] == 4) s = s+'c';
if(v[i] == 5) s = s+'g';
if(v[i] == 6) s = s+'o';
}
if(zakoncz) cout<<"NIE"<<"\n";
else cout<<s<<"\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 | #include <bits/stdc++.h> using namespace std; int n,sr; vector<int> v; string s; bool zakoncz; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; for(int i = 0; i < n; i++){ int jed = 0, zer = 0; for(int j = 0; j < 8; j++){ char x; cin>>x; if(x == '1') jed++; else zer++; } v.push_back(jed); sr+=jed; } // for(int i = 0; i < n; i++) cout<<"w "<<i+1<<" literce jest "<<v[i]<<" jedynek"<<endl; sr/=n; if(sr < 3 || sr > 6){ cout<<"NIE"<<"\n"; return 0; } sort(v.begin(),v.end()); int pula = 0; for(int i = 0; i < n; i++){ if(v[i] > sr) pula+=v[i]-sr, v[i] = sr; } int i = 0; while(v[i] < sr){ // cerr<<"SREDNIA = "<<sr<<endl; // cerr<<"w literce "<<i<<" jest ponizej sredniej wiec dodaje tam "<<abs(sr-v[i])<<endl; pula-= abs(sr-v[i]); v[i] = sr; i++; } i = 0; while(pula > 0){ i = 0; // cerr<<"pula ciagle jest > 0 wiec rozdaje reszte"<<endl; while(pula > 0 && i < n) v[i]++, pula--, i++; } for(int i = 0; i < n; i++){ if(v[i] > 6) zakoncz = true; if(v[i] == 3) s = s+'a'; if(v[i] == 4) s = s+'c'; if(v[i] == 5) s = s+'g'; if(v[i] == 6) s = s+'o'; } if(zakoncz) cout<<"NIE"<<"\n"; else cout<<s<<"\n"; return 0; } |
English