Description Title
you matchsticks n, the number of the form "A + B = C" can you spell the equation? Equation A, B, C is an integer with a match stick spell (if the number of non-zero, then the most significant bit is not 0). Fight of spelling with 0-9 shown in FIG matchstick:
note:
Plus an equal sign and each require two matchstick
If A ≠ B, then A + B = C and B + A = C as different equations (A, B, C> = 0)
n-matchsticks must all spend
input and output format
input format:
A total line, and an integer n (n <= 24).
Output formats:
Total output file matches.out line, represents the number of different equations could spell.
Input Output Sample
Input Sample # 1:
14
Output Sample # 1:
2
Input Sample # 2:
18
Output Sample # 2:
9
----------------
ideas: 1-1000 put that out on the line
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
int a[2000]={6},k[10]={6,2,5,5,4,5,6,3,7,6},b,s=0,i,t;
scanf("%d",&b);
for(i=1;i<=2000;i++)
{
t=i;
while(t>=1)//求每个数所用的火柴棒
{
a[i]=a[i]+k[t%10];
t/=10;
}
}
for(i=0;i<=1000;i++)
{
for(int j=0;j<=1000;j++)
if(a[i]+a[j]+a[i+j]+4 == b)//还有加号与等号
s++;
}
printf("%d",s);
return 0;
}