// gcc1.cpp : Defines the entry point for the console application.
/*
1. 给定等式 A B C D E 其中每个字母代表一个数字,且不同数字对应不
D F G 同字母。编程求出这些数字并且打出这个数字的
+ D F G 算术计算竖式。
───────
X Y Z D E
*/
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
int f=5,g=0,a,b,c,d,e,x,y,z=0;
void Search(int n)
{
for(c=1;c<10;c++)
{
if(c==5) continue;
for(d=1;d<10;d++)
{
if(d==5) continue;
for(e=1;e<10;e++)
{
if(e==5) continue;
for(z=1;z<10;z++)
{
if(z==5) continue;
if(c+2*d+1==10*n+z)
if(a!=b&&a!=c&&a!=d&&a!=e&&a!=x&&a!=y&&a!=z)
if(b!=c&&b!=d&&b!=e&&b!=x&&b!=y&&b!=z)
if(c!=d&&c!=e&&c!=x&&c!=y&&c!=z)
if(d!=e&&d!=x&&d!=y&&d!=z)
if(e!=x&&e!=y&&e!=z)
if(x!=y&&x!=z)
if(y!=z)
if(a+b+c+d+e+x+y+z==40)
{
printf(" %d %d %d %d %d\n",a,b,c,d,e);
printf(" %d %d %d\n",d,f,g);
printf("+ %d %d %d\n",d,f,g);
printf("_____________________\n");
printf(" %d %d %d %d %d\n",x,y,z,d,e);
printf("\n");
printf("\n");
}
}
}
}
}
}
int main()
{
for(a=1;a<10;a++)
{
if(a==4||a==5) continue;
for(x=1;x<10;x++)
{
if(a+1!=x) continue;
if(x==1||x==5||x==6) continue;
for(y=1;y<10;y++)
{
if(y==5) continue;
for(b=1;b<10;b++)
{
if(b==5) continue;
if(y+10-b==1)
{
Search(1);
}
else if(y-b+10==2)
{
Search(2);
}
else continue;
}
}
}
}
getchar();
return 0;
}
评论