题解 | 小红的字符串修改

小红的字符串修改

https://www.nowcoder.com/practice/66e0054ff6b345afa47bcd4e8ceb72d7

#include <iostream>
#include <string>
#include <set>
using namespace std;

int main() {
    std::string fatherstring;
    std::string substring;

    cin >> substring >> fatherstring;
    
    
    //win1
    int lengthsubstr = substring.size();
    int lengthdiff = fatherstring.size() - lengthsubstr;
    std::set<int> exchangetimes;
    for (int i = 0 ;i<lengthdiff;i++)
    {
        int sumtimes = 0;
        for (int s = 0; s < lengthsubstr; s++)
        {
            sumtimes += 26 - abs(substring[s] - fatherstring[i + s]) > abs(substring[s] - fatherstring[i + s]) ? abs(substring[s] - fatherstring[i + s]) : 26 - abs(substring[s] - fatherstring[i + s]);
        }
        exchangetimes.insert(sumtimes);
    }
    cout << *exchangetimes.begin()<< endl;

    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
03-30 21:35
爱蜜莉雅碳劝退测开:裁员裁大动脉了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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