题解 | #游游的整数切割#

游游的整数切割

https://www.nowcoder.com/practice/c01b07fe9623425a806c85cdb6f0e0f7

不论怎么分割 都是在与最后一位数相加 只需要判断当前切割到的左边数字和字符串尾部数字相加是否为偶数

#include <iostream>
using namespace std;

int main() {
    string s;
    cin >> s;
    int last = s.back();
    s.pop_back();
    int cnt = 0;
    for(char c : s){
        if((c - '0' + last) % 2 == 0) cnt ++;
    }
    cout << cnt;
}

全部评论

相关推荐

投递长鑫存储等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务