子串: 对于字符串长度为n的字符串,下标为0,1,…,n-1, 子串是指一段连续的下标L,L+1,…,R(0<=L<=R<n)所对应的字符串,例如abc,那么子串有a,b,c,ab,bc,abc 输入数据量较大,建议使用scanf/printf #include<cstdio> #include<string.h> using namespace std; char words[100005]; int ans[1000]; int main() { int T; scanf("%d",&T); while(T--){ int n,k; scanf("%d%d",&n,&k); memset(words,0,sizeof(words)); memset(ans,0,sizeof(ans)); scanf("%s",words); int p=0; //start int cnt = 0; int flag = 0; for(int i=0;i<n;i++){ //end int temp = words[i]; if(ans[temp] < k){ ans[temp]++; if(ans[temp]==k){ cnt++; } } else{ for(int j=p;j<i;j++){ int t = words[j]; ans[t]--; if(ans[t] == k-1){ cnt--; } if(words[j] == words[i]){ cnt++; ans[t]++; p = j+1; break; } } } if(cnt == 26){ printf("YES\n"); flag = 1; break; } } if(flag != 1){ printf("NO\n"); } } return 0; }
