B题求助
#include <bits/stdc++.h> using namespace std; int lll[26]; int main() { int t,k,num=0,ans=50***00; string s; int d; cin>>t; for(int p=0;p<t;p++) { cin>>s>>k; ans=50***00; memset(lll,0,sizeof lll); int l=s.length(); for(int i=0;i<l;i++) { lll[s[i]-'a']++; if(lll[s[i]-'a']>=k) { d=lll[s[i]-'a']-k; for (int j = 0; j < 26; j++) { if (s[j] == s[i]) { num = abs(i - j+1); ans=min(num,ans); if(d==0) break; else d--; } } } } if(ans==50***00) cout<<"-1\n"; else cout<<ans<<endl; } }