题解 | 游游的整数切割

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            int result = 0;
            /**
            5 952399
            59 52399
            595 2399
            5952 399
            59523 99
            595239 9
             */
            for(int i = 1; i < str.length(); i++) {
                String left = str.substring(0,i);
                String right = str.substring(i);
			   // 只需要证明截取后的2位数的最后一位加起来跟2取模是否等于0
                int l = left.charAt(left.length() - 1)% 2;
                int r = right.charAt(right.length() - 1)%2;
                if((l + r) % 2 == 0) {
                    result++;
                }
            }
            System.out.println(result);
        }
    }
}

全部评论

相关推荐

码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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