XX法习题
题目:给你n根火柴棒,你可以拼出多少个形式如"A+B=C"的等式?#include<stdio.h>
int main()
{
//You kown this...
int i,j,k,n,x,ans = 0;
printf("请输入n: ");
scanf("%d",&n);
int f = {0};
f = 6;f = 2;f = 5;f = 5;f = 4;
f = 5;f = 6;f = 3;f = 7;f = 6;
for(i = 10;i<=1000;i++)//1~1000
{
x = i;
while(x>0)
{
f = f+f;
x = x/10;
}
}
n = n-4;//减去符号
for(i = 0;i<=1000;i++)//列举A
{
if(f<n)//如果还足够的话
{
for(j = 0;j<=1000;j++)//列举B
{
if(f+f<n){//还敢
k = i+j;
if(f+f+f == n)//如果天时不如地利,地利不如人和。。
{
ans++;
}
}
}
}
}
printf("ans = %d\n",ans);
return 0;
}
页:
[1]