fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main(){
  5.  
  6. int k;
  7. cin>>k;
  8. string a;
  9. cin>>a;
  10. int count[26];
  11. int l=a.size();
  12. if(l%k!=0 || l<k){
  13. cout<<-1;
  14. return 0;
  15. }
  16.  
  17. for(int i=0;i<26;i++)
  18. count[i]=0;
  19.  
  20. for(int i=0;i<l;i++){
  21. count[a[i]-97]++;
  22.  
  23. }
  24.  
  25.  
  26.  
  27.  
  28. for(int i=0;i<26;i++){
  29. if(count[i]%k!=0 && count[i]!=0){
  30. cout<<-1;
  31. return 0;
  32. }}
  33. int pos=0;
  34.  
  35. for(int i=0;i<l;pos++){
  36.  
  37. if(count[pos]%k==0 && count[pos]!=0){
  38. for(int j=0;j<count[pos]/k;j++)
  39. cout<<(char)(pos+97);
  40. i++;
  41. }
  42. if(pos==25)
  43. pos=-1;
  44.  
  45.  
  46. }
  47. return 0;
  48. }
  49.  
  50.  
Success #stdin #stdout 0s 3472KB
stdin
2
aazz
stdout
azaz