fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14. int t;
  15. cin>>t;
  16. while(t--){
  17. int ks;
  18. cin>>ks;
  19. string k;
  20. cin>>k;
  21. int mina=k.length();
  22. string g="";
  23. for(int i=0;i<k.length();i++){
  24. g.push_back(k[i]);
  25. if(k.length()%g.length()==0)
  26. {
  27.  
  28. string ff=g;
  29. for(int f=0;f<(k.length()/g.length())-1;f++){
  30. ff+=g;
  31. }
  32. int count=0;
  33. for(int i=0;i<k.length();i++){
  34. if(k[i]!=ff[i]){
  35. count++;
  36. }
  37. if(count>1){
  38. break;
  39. }
  40. }
  41. cout<<g<<' '<<ff<<' '<<count<<endl;
  42. if(count==1 || count==0){
  43. if(g.length()<mina){
  44. mina=g.length();
  45. }
  46. }
  47. }
  48. }
  49. cout<<mina<<endl;
  50. }
  51. return 0;
  52. }
Success #stdin #stdout 0.01s 5304KB
stdin
5
4
abaa
4
abba
13
slavicgslavic
8
hshahaha
20
stormflamestornflame
stdout
a aaaa 1
ab abab 1
abaa abaa 0
1
a aaaa 2
ab abab 2
abba abba 0
4
s sssssssssssss 2
slavicgslavic slavicgslavic 0
13
h hhhhhhhh 2
hs hshshshs 2
hsha hshahsha 1
hshahaha hshahaha 0
4
s ssssssssssssssssssss 2
st stststststststststst 2
stor storstorstorstorstor 2
storm stormstormstormstorm 2
stormflame stormflamestormflame 1
stormflamestornflame stormflamestornflame 0
10