fork download
  1. #include <iostream>
  2. #include<string>
  3. #include<vector>
  4. #include<map>
  5. using namespace std;
  6.  
  7. bool findutil(string &temp,map<string,int> &hash,const vector<string> &B,int start,int end)
  8. {
  9. int i=0,j=0;
  10. int len=B.size();
  11. int len1=B[0].size();
  12.  
  13. while(i<len)
  14. {
  15. hash[B[i]]=0;
  16. i++;
  17. }
  18. i=start;
  19. while(i<=(end-len1+1))
  20. {
  21. if(hash.find(temp.substr(i,len1))==hash.end())
  22. return false;
  23. else
  24. {
  25. if(hash[temp.substr(i,len1)]==1)
  26. return false;
  27. else
  28. hash[temp.substr(i,len1)]=1;
  29. i+=len1;
  30. }
  31. }
  32. return true;
  33.  
  34. }
  35. int main() {
  36. // your code goes here
  37. const char* args[] = {"foo", "bar"};
  38. std::vector<std::string> B(args, args + 2);
  39. string A="barfoothefoobarman ";
  40. // vector<string> B=[ "aaa", "aaa", "aaa", "aaa", "aaa" ];
  41.  
  42.  
  43. int i=0,j=0,len=0,count=0,total=0,len1=0;
  44. vector<int>res;
  45. map<string,int> hash;
  46. len1=A.size();
  47. len=B.size();
  48. count=B[0].length();
  49. total=count*len;
  50.  
  51. i=0;
  52. while(i<len)
  53. {
  54. hash[B[i]]=0;
  55. i++;
  56. }
  57. i=0;
  58. while(i<=(len1-total+1))
  59. {
  60.  
  61. j=i+total-1;
  62.  
  63. if(findutil(A,hash,B,i,j))
  64. {
  65. res.push_back(i);
  66. }
  67. i++;
  68.  
  69. }
  70. i=0;
  71. while(i<res.size())
  72. {
  73. cout<<res[i]<<endl;
  74. i++;
  75. }
  76. return 0;
  77. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
0
9