You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
533 B
C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[1050];
int pre[256];
int main()
{
int T;
scanf("%d", &T);
for (int t = 1; t <= T; t++)
{
scanf("%s", s);
memset(pre, -1, sizeof(pre));
unsigned ans = -1;
int n = strlen(s);
for (int i = 0; i < n; i++)
{
if (pre[s[i]] != -1)
ans = min<unsigned>(ans, i - pre[s[i]]);
pre[s[i]] = i;
}
printf("Case #%d: %d\n", t, ans);
}
return 0;
}