Untitled
unknown
c_cpp
16 days ago
745 B
1
Indexable
Never
#include <iostream> #include <string> #include <cstdlib> // 用于 llabs 函数 using namespace std; int main() { string n_str; cin >> n_str; string odd_digits = ""; string even_digits = ""; // 分离奇数位和偶数位 for (char ch : n_str) { int digit = ch - '0'; if (digit % 2 == 1) { odd_digits += ch; } else { even_digits += ch; } } // 将字符串转换为数字 long long odd_number = odd_digits.empty() ? 0 : stoll(odd_digits); long long even_number = even_digits.empty() ? 0 : stoll(even_digits); // 计算并输出绝对值差 long long result = llabs(odd_number - even_number); cout << result << endl; return 0; }
Leave a Comment