字符串。
1 #include <cstdio> 2 #include <cstring> 3 4 int visit[130]; 5 char s[1000005]; 6 7 int main() { 8 int n, len; 9 int i, j, k, tmp, l; 10 11 while (scanf("%d%*c", &n)!=EOF && n) { 12 gets(s+1); 13 memset(visit, 0, sizeof(visit)); 14 len = tmp = 0; 15 for (i=k=1; s[i]; ++i) { 16 if (visit[s[i]] == 0) { 17 ++tmp; 18 if (tmp>n && i-k>len) 19 len = i - k; 20 while (tmp > n) { 21 if (--visit[s[k]] == 0) 22 --tmp; 23 ++k; 24 } 25 } 26 visit[s[i]]++; 27 } 28 if (i-k > len) 29 len = i - k; 30 printf("%d\n", len); 31 } 32 33 return 0; 34 }
【HDOJ】2369 Broken Keyboard,布布扣,bubuko.com
原文:http://www.cnblogs.com/bombe1013/p/3860187.html