#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
string s;
cin>>s;
int ctr=0;
vector<char>mp(7,'a');
//mp[3]=a;
mp[4]='c';
mp[5]='k';
mp[6]='w';
for(auto const &w : s){
if(w=='1'){
ctr++;
}
}
if(ctr<3*n||ctr>6*n){
cout<<"NIE"<<'\n';
return 0;
}
int lower=ctr/n;// co jak jest pelna liczba
if(ctr%n==0){
while(n--){
cout<<mp[lower];
}
return 0;
}
int upper=lower+1;
int outleft=n;
while(!(outleft*lower==ctr)){
cout<<mp[upper];
ctr-=upper;
outleft--;
}
while(outleft>0){
cout<<mp[lower];
outleft--;
}
}
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; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; string s; cin>>s; int ctr=0; vector<char>mp(7,'a'); //mp[3]=a; mp[4]='c'; mp[5]='k'; mp[6]='w'; for(auto const &w : s){ if(w=='1'){ ctr++; } } if(ctr<3*n||ctr>6*n){ cout<<"NIE"<<'\n'; return 0; } int lower=ctr/n;// co jak jest pelna liczba if(ctr%n==0){ while(n--){ cout<<mp[lower]; } return 0; } int upper=lower+1; int outleft=n; while(!(outleft*lower==ctr)){ cout<<mp[upper]; ctr-=upper; outleft--; } while(outleft>0){ cout<<mp[lower]; outleft--; } } |
English