【算法】程序猿不写代码是不对的62
2017-05-25 17:44
309 查看
package com.kingdz.algorithm.time201705; /** * <pre> * 摆火柴 * 有N个火柴,摆成A+B=C的形式 * 其中从0到9需要的火柴数分别是6,2,5,5,4,5,6,3,7,6 * 求根据给定的N求出可以有多少种摆法 * </pre> * * @author kingdz * */ public class Algo25 { private static int[] fire = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 }; public static void main(String[] args) { int n = 18; int sum = 0; for (int a = 0; a <= 1111; a++) { for (int b = 0; b < 1111; b++) { int c = a + b; if (fn(a) + fn(b) + fn(c) == n - 4) { System.out.println("" + a + "+" + b + "=" + c + ""); sum++; } } } System.out.println(sum); } /** * 返回数X需要的火柴数目 * */ private static int fn(int x) { int count = 0; String num = "" + x; for (char c : num.toCharArray()) { int index = Integer.parseInt("" + c); count = count + fire[index]; } return count; } }
相关文章推荐
- 【算法】程序猿不写代码是不对的3
- 【算法】程序猿不写代码是不对的6
- 【算法】程序猿不写代码是不对的26
- 【算法】程序猿不写代码是不对的32
- 【算法】程序猿不写代码是不对的31
- 【算法】程序猿不写代码是不对的1
- 【算法】程序猿不写代码是不对的36
- 【算法】程序猿不写代码是不对的22
- 【算法】程序猿不写代码是不对的21
- 【算法】程序猿不写代码是不对的34
- 【算法】程序猿不写代码是不对的7
- 【算法】程序猿不写代码是不对的13
- 【算法】程序猿不写代码是不对的12
- 【算法】程序猿不写代码是不对的24
- 【算法】程序猿不写代码是不对的18
- 【算法】程序猿不写代码是不对的5
- 【算法】程序猿不写代码是不对的11
- 【算法】程序猿不写代码是不对的15
- 【算法】程序猿不写代码是不对的29
- 【算法】程序猿不写代码是不对的35