2019/10/8今日头条笔试

2019/10/8今日头条笔试 第三题

public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int num = Integer.parseInt(scanner.nextLine()); for(int i=0; i<num; i++) { String s = scanner.nextLine(); getZeroNumber(s, 0, 0, 0, true); System.out.println(number); number = 0; } } private static int number = 0; private static void getZeroNumber(String s, int start, int now, int sum, boolean minus) { String subS = s.substring(start, now); if(subS.length() >= 1) { long subSum = Long.parseLong(subS); if (!minus) { sum += subSum; } else { sum -= subSum; } } if (now >= s.length() && start != 0) { if (sum == 0) { number++; } return; } for (int i = now+1; i <= s.length(); i++) { getZeroNumber(s, now, i, sum, true); getZeroNumber(s, now, i, sum, false); } } 
全部评论

相关推荐

爱看电影的杨桃allin春招:我感觉你在炫耀
点赞 评论 收藏
分享
4 4 评论
分享
牛客网
牛客企业服务