如題
如題
t/6g4a83#includeusing namespace std;
int main(){string str;while (cin >> str){long double a_a = 0, b_b = 0, i_str = 0;long long int minum;double a[str.size()], b[str.size()];for (int i = 0; i < str.size(); i++){if ((str[i] - '0') % 2 != 1){a[i] = str[i] - '0' + 1;if (str[i] == '0'){if (b[i - 1] == 1 || b[i - 1] == 3 || b[i - 1] == 5 || b[i - 1] == 7 || b[i - 1] == 9){if (b[i - 1] == 1){b[i - 1] -= 1;}else{b[i - 1] -= 2;}}else{b[i - 1] -= 1;}b[i] = 9;}else{b[i] = str[i] - '0' - 1;}for (int j = i + 1; j < str.size(); j++){a[j] = 1;b[j] = 9;}break;}else{a[i] = str[i] - '0';b[i] = str[i] - '0';}}for (int i = str.size(); i > 0 ; i--){a_a += a[str.size() - i] * pow(10, i - 1);b_b += b[str.size() - i] * pow(10, i - 1);i_str += (str[str.size() - i] - '0') * pow(10, i - 1);}minum = (long long int)(min(a_a - i_str, i_str - b_b) + 0.5 - (min(a_a - i_str, i_str - b_b) < 0));cout << minum << endl;}
return 0;}
已解決