#include <algorithm> #include <iostream> using namespace std; int search(char *text){ int lastpos[256], lmax=0, curmax=0; for(int i=0;i<256;i++) lastpos[i]=-1; for(int i=0; text[i]; i++){ if(i-lastpos[ text[i] ] > curmax){ curmax++; lmax = max(lmax, curmax); } else curmax = i-lastpos[ text[i] ]; lastpos[ text[i] ] = i; } return lmax; } int main(){ char raw[] = "xabcdabxb"; cout<<search(raw)<<endl; return 0; }