title: C++ - search duplicate strings in large text
body: <p>My aim is to find all duplicate strings of any length in the text (matched strings should not intersect). For this purpose I use the following code</p>
  
  <pre><code>   #include &lt;string&gt;
     using namespace std;
  
     int main()
     {
        string text = "j73vd6hdk9382haswm03hs84mmsg73flw94ncjd93k9dj3ndi5jf95j";
        int len =  text.length();
  
           for(int m=0;m&lt;len-1;m++)
           {
             int h_len=(len-m)/2;
  
             for(int i=0;i&lt;h_len;i++)
             {
                string a1 = text.substr(m,i+1);
                for(int k=0;k&lt;len-2*i-1-m;k++)
                {
                    string a2 = text.substr(i+1+k+m,i+1);
                    if(a1==a2) { /* do something */ }
                }
  
             }
           }
  
       return 0;     
     }    
  </code></pre>
  
  <p>the script works but when the text size increases, the time of execution extremely increases  as well.  The program is too slow. How can I speed up my program? Can you give me any suggestion to improve the code? Maybe there is a better algorithm to do that. </p>