fork download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. int Length(string s)
  7. {
  8. int len=0;
  9. for(int i=0;s[i]!='\0';i++)
  10. {
  11. len++;
  12. }
  13. return len;
  14. }
  15. vector<int>substringfind(string s,string sub)
  16. {
  17. int lens=Length(s);
  18. int lensub=Length(sub);
  19. vector<int>pos;
  20. int paisi=0;
  21. for(int i=0;i<=lens-lensub;i++)
  22. {
  23. int matched=0;
  24. for(int j=0;j<lensub;j++)
  25. {
  26. if(sub[j]==s[i+j])
  27. {
  28. matched++;
  29. continue;
  30. }
  31. else
  32. break;
  33. }
  34. if(matched==lensub)
  35. {
  36. pos.push_back(i);
  37. }
  38. }
  39. return pos;
  40. }
  41. int main()
  42. {
  43. string s,sub;
  44. cin>>s>>sub;
  45. vector<int>position=substringfind(s,sub);
  46. for(int i=0;i<position.size();i++)
  47. {
  48. cout<<position[i];
  49. }
  50. cout<<endl;
  51. return 0;
  52. }
Success #stdin #stdout 0s 5264KB
stdin
jhumuma
um
stdout
24