题解 | 小红的字符串修改
小红的字符串修改
https://www.nowcoder.com/practice/66e0054ff6b345afa47bcd4e8ceb72d7
#include <stdio.h>
#include <string.h>
int main()
{
char s[1001] = { '\0' };
char t[1001] = { '\0' };
scanf("%s", s);
scanf("%s", t);
int szs = strlen(s);
int szt = strlen(t);
unsigned int ans = 999999999;
unsigned int count = 0;
for (int i = 0; i <= szt - szs; i++)
{
for (int j = i; j < i + szs; j++)
{
int dif = 0;
dif = s[j - i] - t[j];
if (dif < 0)
dif = -dif;
if (dif > 13)
dif = 26 - dif;
count += dif;
}
if (ans > count)
{
ans = count;
}
count = 0;
}
printf("%u\n", ans);
return 0;
}

