c++字符数组 第一个不相同字符的ASCII码值之差

img

img

img


救救孩子吧
孩子不知道这个代码哪里出问题了


#include <iostream>

using namespace std;

int main()
{
    string s1,s2;
    cin >> s1;
    cin >> s2;
    for(int i = 0;i < min(s1.length(),s2.length());i++){
        if(s1.at(i) != s2.at(i)){
            cout << abs(s1.at(i) - s2.at(i)) << endl;
            return 0;
        }
    }
    if(s1.length() > s2.length()){
        cout << abs(s1.at(s1.length() - 1) - '\0') << endl;
    }else if(s1.length() < s2.length()){
        cout << abs(s2.at(s2.length() - 1) - '\0') << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}