2435: 【普及-】【P1149】火柴棒等式

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:6 解决:3

题目描述

给你 lns="http://www.w3.org/1998/Math/MathML"> 根火柴棍,你可以拼出多少个形如 lns="http://www.w3.org/1998/Math/MathML">+= 的等式?等式中的 lns="http://www.w3.org/1998/Math/MathML">lns="http://www.w3.org/1998/Math/MathML">lns="http://www.w3.org/1998/Math/MathML"> 是用火柴棍拼出的整数(若该数非零,则最高位不能是 lns="http://www.w3.org/1998/Math/MathML">0)。用火柴棍拼数字 lns="http://www.w3.org/1998/Math/MathML">09 的拼法如图所示:

注意:

  1. 加号与等号各自需要两根火柴棍;

  2. 如果 lns="http://www.w3.org/1998/Math/MathML">,则 lns="http://www.w3.org/1998/Math/MathML">+= 与 lns="http://www.w3.org/1998/Math/MathML">+= 视为不同的等式(lns="http://www.w3.org/1998/Math/MathML">,,0);

  3. lns="http://www.w3.org/1998/Math/MathML"> 根火柴棍必须全部用上。

输入

一个整数 lns="http://www.w3.org/1998/Math/MathML">(124)

输出

一个整数,能拼成的不同等式的数目。

样例输入 复制

14

样例输出 复制

2

提示

【输入输出样例 1 解释】

lns="http://www.w3.org/1998/Math/MathML">2 个等式为 lns="http://www.w3.org/1998/Math/MathML">0+1=1 和 lns="http://www.w3.org/1998/Math/MathML">1+0=1

【输入输出样例 2 解释】

样例输入:18

样例输出:9

lns="http://www.w3.org/1998/Math/MathML">9 个等式为

lns="http://www.w3.org/1998/Math/MathML">0+4=4lns="http://www.w3.org/1998/Math/MathML">0+11=11lns="http://www.w3.org/1998/Math/MathML">1+10=11lns="http://www.w3.org/1998/Math/MathML">2+2=4lns="http://www.w3.org/1998/Math/MathML">2+7=9lns="http://www.w3.org/1998/Math/MathML">4+0=4lns="http://www.w3.org/1998/Math/MathML">7+2=9lns="http://www.w3.org/1998/Math/MathML">10+1=11lns="http://www.w3.org/1998/Math/MathML">11+0=11


#include<bits/stdc++.h>
using namespace std;

int main(){
	int m[10]={6,2,5,5,4,5,6,3,7,6};
	int n,ans=0;
	cin>>n;
	for (int i=0;i<=1111;i++) {
		for (int j=0;j<=1111;j++) {
			    int k=i+j;
				int s=0;
				int a=i,b=j,c=k;
				do {
					s+=m[a%10];
					a/=10;
				}while (a>0);
				do {
					s+=m[b%10];
					b/=10;
				}while (b>0);
				do {
					s+=m[c%10];
					c/=10;
				}while (c>0);						
				if (s==(n-4)) {
					//cout<<i<<"+"<<j<<"="<<k<<endl;
					ans++;
				}												    
		}
	}
	cout<<ans<<endl;
	return 0;
}