//You just need to find the longest dup string from the src string. 

#include 
<iostream>
#include 
<string>
using namespace std;

typedef 
char* PCHAR;
int GetLongestDupStr(string src, string &dst)
{
    
int lenth = src.length();
    
string temp;
    
int index1 = 0;
    
int index2 = 0;
    
for(int i = lenth - 1; i > 0; i--)
    
{
        
for(int j = 0; j < lenth; j++)
        
{
            
if( i + j <= lenth)
            
{
                temp 
= src.substr(j, i);
                index1 
= src.find(temp);
                index2 
= src.rfind(temp);
                
if(index1 != index2)
                
{
                    dst 
= temp;
                    cout
<<index1<<" "<<dst<<endl;
                    
return index1;
                }

            }

            cout
<<temp<<endl;
        }

    }

    
return 0;
}


void main()
{
    
string src = "abcdefg";
    
string dst;
    
int count = GetLongestDupStr(src, dst);
    cin
>>count;
}
posted on 2009-06-08 14:29  Jackill  阅读(165)  评论(0编辑  收藏  举报