题解 | 小红的字符串修改

小红的字符串修改

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;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务