analysis
If we can’t judge that there must be repeated letters.
We can find a property: when the distance between the first pair of repeated letters is <=k, it can’t be judged. For
example, if S=“SASS” and k=2, if AS is left You can delete 1, 3 or 1, 4, so it can't be judged.
Then the first pair is 1, 3 and the distance is 2.
Upload code
#include<iostream>
#include<cstdio>
using namespace std;
int n,k,ff;
string s;
int main()
{
cin>>n;
while(n--)
{
ff=0;
cin>>s;
cin>>k;
if(k==s.length())
{
cout<<"Certain"<<endl;
continue;
}
for(int i=0;i<=s.length()-1;i++)
{
for(int j=i+1;j<=s.length()-1;j++)
{
if(s[i]==s[j])
{
int t=j-i;
if(t<=k)
{
ff=1;
cout<<"Uncertain"<<endl;
break;
}
}
}
if(ff==1) break;
}
if(ff==0) cout<<"Certain"<<endl;
}
return 0;
}