题意:
给定一段只包含“1”“2”“3”的字符串,求其中包含三个数字的连续子串的最小长度。
AC代码:
int a, b, c;
int main()
{
int t;
sd(t);
while (t--)
{
string s;
cin >> s;
int len = s.size();
int ans = inf;
a = inf, b = inf, c = inf;
rep(i, 0, len - 1)
{
if (s[i] == '1')
a = i;
if (s[i] == '2')
b = i;
if (s[i] == '3')
c = i;
ans =min(ans, max({a, b, c}) - min({a, b, c}) + 1);
}
cout << (ans >200000 ? 0 : ans) << endl;
}
return 0;
}