9-degree oj 1530 longest non-duplicate substring, oj1530
Original question link: http://ac.jobdu.com/problem.php? Pid = 1, 1530
The string is simple. It seems that the complexity of O (n ^ 2) is 10000 of the data size. In fact, the maximum number of non-repeated substrings cannot exceed 26...
As follows:
1 # include <algorithm> 2 # include <iostream> 3 # include <cstdlib> 4 # include <cstring> 5 # include <cstdio> 6 using std: max; 7 const int Max_N = 10010; 8 int vis [26]; 9 char buf [Max_N]; 10 void solve () {11 int I, j, ans = 0, n = strlen (buf); 12 for (I = 0; I <n-1; I ++) {13 int t = 1; 14 memset (vis, 0, sizeof (vis); 15 vis [buf [I]-'a'] = 1; 16 for (j = I + 1; j <n; j ++) {17 if (! Vis [buf [j]-'a']) {18 vis [buf [j]-'a'] = 1; 19 t ++; 20} else {21 break; 22} 23} 24 ans = max (ans, t); 25} 26 printf ("% d \ n", ans); 27} 28 int main () {29 # ifdef LOCAL30 freopen ("in.txt", "r", stdin); 31 freopen ("out.txt", "w +", stdout); 32 # endif33 while (~ Scanf ("% s", buf) solve (); 34 return 0; 35} View Code