#include <bits/stdc++.h>
using namespace std;
signed main(){
string n;
int A, B, a, b;
cin >> n;
A = 0;
B = 0;
int len = n.size();
for( int i = 0 ; i < len ; i++ ){
if( i % 2 == 0 ){
a = (int)n[len - 1 - i] - 48;
A = A + a;
}
else{
b = (int)n[len - 1 - i] - 48;
B = B + b;
}
}
if( A > B ){
cout << A - B;
}
else{
cout << B - A;
}
}
程式碼解釋
這是我的Hackmd,這是這一天解答的詳細解釋連結,有興趣的人可以點進來來看看
https://hackmd.io/@yqvHTthmTYehjxz4k9Hqrw/rJfpf_tNF