ishanra

Untitled

Oct 24th, 2021 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. set<string> split(string s, int frag)
  2. {
  3. set<string> uni;
  4. int len = s.length();
  5. for(int i = 0; i < len; i+= frag)
  6. {
  7. uni.insert(s.substr(i, frag));
  8. }
  9.  
  10. return uni;
  11. }
  12.  
  13. bool check(string str,string out)
  14. {
  15. for(int i=0;i<out.size();i++)
  16. {
  17. if(str[i]!=out[i] && str[i]!='#')
  18. return 0;
  19. }
  20. return 1;
  21. }
  22.  
  23. int main()
  24. {
  25. #ifndef ONLINE_JUDGE
  26. freopen("input.txt", "r", stdin);
  27. freopen("output.txt", "w", stdout);
  28. #endif
  29. ios_base::sync_with_stdio(0);
  30. cin.tie(NULL);
  31. cout.tie(NULL);
  32.  
  33. string out;
  34. string s;
  35. cin>>s;
  36. int len = s.length();
  37.  
  38. for(int i = len/2; i>1;--i)
  39. {
  40. set<string> uni = split(s,i);
  41. if(uni.size() == 1)
  42. {
  43. out = *uni.begin();
  44. break;
  45. }
  46. }
  47.  
  48. int n=out.length();
  49.  
  50. int i=0;
  51.  
  52. string res="";
  53.  
  54. while(i+n<len)
  55. {
  56. string str=s.substr(i,i+n);
  57. if(check(str,out))
  58. {
  59. res+=((i+1)-'0');
  60. }
  61. i++;
  62. }
  63.  
  64. return 0;
  65.  
  66. }
Add Comment
Please, Sign In to add comment