P1149 [NOIP2008 提高组] 火柴棒等式
public class P1149 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
search(scanner.nextInt());
}
public static void search(int n) {// 先写框架后补函数
int sum = 0;
for (int a = 0; a <= 720; a++) {
for (int b = 0; b <= 720; b++) {
if (f(a) + f(b) + f(a + b) == n - 4) {
sum++;
}
}
}
System.out.println(sum);
}
public static int f(int n) {
if (n == 0) {
return 6;
}
int sum = 0;
int[] a = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
while (n != 0) {// 数位拆分
sum += a[n % 10];
n /= 10;
}
return sum;
}
}