呵呵,我有那里的帐号,去看看
重剑无锋,大巧不工
#include<stdio.h> #include<stdlib.h> #include<string.h> int cmp(const void * a, const void * b) { return strcmp(*(char **)a, *(char **)b); } int main() { char w[1024][16], *p[1024], t[16], *tt = t; short int d[1024] = {0}, s[200000]; int n, m, c, len, i, j; for(scanf("%d", &n), i = 0; i < n; p[i] = w[i], i++) scanf("%s", w[i]); qsort(p, n, sizeof(char *), cmp); for(scanf("%d", &m), i = 0; i < m && scanf("%s", t); i++) s[i] = (char **)bsearch(&tt, p, n, sizeof(char *), cmp) - p; for(c = i = j = 0; j < m; j++) { if(s[j] < 0) continue; if(!d[s[j]]++) len = j - i + 1, c++; while(i < j) if(s[i] < 0) i++; else if(d[s[i]] > 1) d[s[i++]]--; else break; if(j - i + 1 < len) len = j - i + 1; } printf("%d\n%d\n", c, (c ? len : 0)); return 0; }