小红划数字
- 关键思路:这个数的个位数字是偶数,那它就是偶数;所以我们可以优先划掉后面的数字,直到遇到偶数为止;
- 不要想的太复杂了;
#include <bits/stdc++.h>
using namespace std;
string nums;
int main() {
cin >> nums;
bool flag = false;
int lenN = nums.size();
int ans = 0;
for (int i = lenN - 1; i >= 0; --i){
int x = nums[i] - '0';
if (x & 1) {
ans++;
continue;
}
else {
flag = true;
break;
}
}
if (flag) printf ("%d", ans);
else cout << -1;
return 0;
}