给定等式 A B C D E 其中每个字母代表一个数字,且不同数字对应不
ABCDEDFG+DFG———————XYZDE没办法自动左对齐了,ABCDE+DFG+DFG=XYZDE这样的,我要过程其中每个字母代表一个数字,且不同数字对应不同字母...
A B C D E
D F G
+ D F G
———————
X Y Z D E
没办法自动左对齐了,ABCDE+DFG+DFG=XYZDE 这样的,我要过程
其中每个字母代表一个数字,且不同数字对应不
同字母。编程求出这些数字并且打出这个数字的
算术计算竖式。
这个题的c语言怎样写 展开
D F G
+ D F G
———————
X Y Z D E
没办法自动左对齐了,ABCDE+DFG+DFG=XYZDE 这样的,我要过程
其中每个字母代表一个数字,且不同数字对应不
同字母。编程求出这些数字并且打出这个数字的
算术计算竖式。
这个题的c语言怎样写 展开
6个回答
展开全部
void NumAnalyse(){
int a,b,c,d,e,f,g,x,y,z;
for(a=0;a<10;a++)
for(b=0;b<10;b++)
if(b==a)
continue;
else
for(c=0;c<10;c++)
if(c==a || c==b)
continue;
else
for(d=0;d<10;d++)
if(d==a || d==b || d==c)
continue;
else
for(e=0;e<10;e++)
if(e==a || e==b || e==c ||e==d)
continue;
else
for(f=0;f<10;f++)
if(f==a || f==b || f==c || f==d || f==e)
continue;
else
for(g=0;g<10;g++)
if(g==a || g==b || g==c || g==d || g==e || g==f)
continue;
else
for(x=0;x<10;x++)
if(x==a || x==b || x==c || x==d ||x==e || x==f || x==g)
continue;
else
for(y=0;y<10;y++)
if(y==a || y==b || y==c ||y==d||y==e||y==f||y==g||y==x)
continue;
else
{
z=45-a-b-c-d-e-f-g-x-y;
if(a*10000+b*1000+c*100+d*10+e + d*100+f*10+g+d*100+f*10+g == x*10000+y*1000+z*100+d*10+e)
printf("a=%d,b=%d,c=%d,d=%d,e=%d,f=%d,g=%d,x=%d,y=%d,z=%d\n",a,b,c,d,e,f,g,x,y,z);
}
}
main()
{
NumAnalyse();
getchar();
}
int a,b,c,d,e,f,g,x,y,z;
for(a=0;a<10;a++)
for(b=0;b<10;b++)
if(b==a)
continue;
else
for(c=0;c<10;c++)
if(c==a || c==b)
continue;
else
for(d=0;d<10;d++)
if(d==a || d==b || d==c)
continue;
else
for(e=0;e<10;e++)
if(e==a || e==b || e==c ||e==d)
continue;
else
for(f=0;f<10;f++)
if(f==a || f==b || f==c || f==d || f==e)
continue;
else
for(g=0;g<10;g++)
if(g==a || g==b || g==c || g==d || g==e || g==f)
continue;
else
for(x=0;x<10;x++)
if(x==a || x==b || x==c || x==d ||x==e || x==f || x==g)
continue;
else
for(y=0;y<10;y++)
if(y==a || y==b || y==c ||y==d||y==e||y==f||y==g||y==x)
continue;
else
{
z=45-a-b-c-d-e-f-g-x-y;
if(a*10000+b*1000+c*100+d*10+e + d*100+f*10+g+d*100+f*10+g == x*10000+y*1000+z*100+d*10+e)
printf("a=%d,b=%d,c=%d,d=%d,e=%d,f=%d,g=%d,x=%d,y=%d,z=%d\n",a,b,c,d,e,f,g,x,y,z);
}
}
main()
{
NumAnalyse();
getchar();
}
展开全部
任意10字母通用程序
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main()
{
char one_line[]="ABCDE+DFG+DFG=XYZDE";
char s[4][6];
int id[4][6];
char c[26];
int i,j,k,n,len[4];
int flag;
long int d[4];
int ii[26];
j = strlen(one_line);
for (i=0;i<j;i++) if (one_line[i] == '+' || one_line[i] == '=' ) one_line[i] = ' ';
sscanf(&one_line[0],"%s %s %s %s",&s[0][0],&s[1][0],&s[2][0],&s[3][0]);
for (i=0;i<4;i++) len[i] = strlen(s[i]);
n=0;
c[n] = s[0][0]; n = n + 1;
for (j=0;j<4;j++){
for (i=0;i<len[j];i++) {
flag = 0;
for (k=0;k<n;k++) { if (s[j][i] == c[k] ) flag = 1; };
if (flag == 0) {c[n] = s[j][i]; n = n + 1;} else { flag = 0;};
};
};
// printf("total diff latters are: %d %s\n",n,c);
for (j=0;j<4;j++)
for (i=0;i<len[j];i++)
for (k=0;k<n;k++) if (s[j][i] == c[k]) { id[j][i] = k; break;};
// subroutine for 10 letters
for (ii[0]=0;ii[0]<10;ii[0]++){
for (ii[1]=0;ii[1]<10;ii[1]++){
if (ii[0] == ii[1]) continue;
for (ii[2]=0;ii[2]<10;ii[2]++){
if (ii[0] == ii[2] || ii[1] == ii[2]) continue;
for (ii[3]=0;ii[3]<10;ii[3]++){
if (ii[0] == ii[3] || ii[1] == ii[3] || ii[2] == ii[3]) continue;
for (ii[4]=0;ii[4]<10;ii[4]++){
if (ii[0] == ii[4] || ii[1] == ii[4] || ii[2] == ii[4] || ii[3] == ii[4]) continue;
for (ii[5]=0;ii[5]<10;ii[5]++){
if (ii[0] == ii[5] || ii[1] == ii[5] || ii[2] == ii[5] || ii[3] == ii[5] || ii[4] == ii[5]) continue;
for (ii[6]=0;ii[6]<10;ii[6]++){
if (ii[0] == ii[6] || ii[1] == ii[6] || ii[2] == ii[6]) continue;
if (ii[3] == ii[6] || ii[4] == ii[6] || ii[5] == ii[6]) continue;
for (ii[7]=0;ii[7]<10;ii[7]++){
if (ii[0] == ii[7] || ii[1] == ii[7] || ii[2] == ii[7]) continue;
if (ii[3] == ii[7] || ii[4] == ii[7] || ii[5] == ii[7] || ii[6] == ii[7]) continue;
for (ii[8]=0;ii[8]<10;ii[8]++){
if (ii[0] == ii[8] || ii[1] == ii[8] || ii[2] == ii[8]|| ii[3] == ii[8]) continue;
if (ii[4] == ii[8] || ii[5] == ii[8] || ii[6] == ii[8] || ii[7] == ii[8]) continue;
for (ii[9]=0;ii[9]<10;ii[9]++){
if (ii[0] == ii[9] || ii[1] == ii[9] || ii[2] == ii[9]|| ii[3] == ii[9]) continue;
if (ii[4] == ii[9] || ii[5] == ii[9] || ii[6] == ii[9] || ii[7] == ii[9]|| ii[8] == ii[9]) continue;
for (j=0;j<4;j++) {
d[j] = 0;
for (i=0;i<len[j];i++) {
d[j] = d[j] + ii[id[j][i]] * pow(10,len[j]-i-1);
}; // for i
}; // for j
if (d[3] != 0 && d[0]+d[1]+d[2] == d[3] && ii[id[0][0]] !=0 && ii[id[1][0]] !=0 && ii[id[2][0]] != 0 && ii[id[3][0]] != 0){
printf("%7d\n%7d\n+%6d\n---------------\n%7d\n",d[0],d[1],d[2],d[3]);
exit(0);
};
}
}}}}}}}}};
}
结果:
ABCDE+DFG+DFG=XYZDE
29786
850
+ 850
---------------
31486
ABCDE+DEF+EFG=XYZDE
19385
854
+ 546
----------
20785
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main()
{
char one_line[]="ABCDE+DFG+DFG=XYZDE";
char s[4][6];
int id[4][6];
char c[26];
int i,j,k,n,len[4];
int flag;
long int d[4];
int ii[26];
j = strlen(one_line);
for (i=0;i<j;i++) if (one_line[i] == '+' || one_line[i] == '=' ) one_line[i] = ' ';
sscanf(&one_line[0],"%s %s %s %s",&s[0][0],&s[1][0],&s[2][0],&s[3][0]);
for (i=0;i<4;i++) len[i] = strlen(s[i]);
n=0;
c[n] = s[0][0]; n = n + 1;
for (j=0;j<4;j++){
for (i=0;i<len[j];i++) {
flag = 0;
for (k=0;k<n;k++) { if (s[j][i] == c[k] ) flag = 1; };
if (flag == 0) {c[n] = s[j][i]; n = n + 1;} else { flag = 0;};
};
};
// printf("total diff latters are: %d %s\n",n,c);
for (j=0;j<4;j++)
for (i=0;i<len[j];i++)
for (k=0;k<n;k++) if (s[j][i] == c[k]) { id[j][i] = k; break;};
// subroutine for 10 letters
for (ii[0]=0;ii[0]<10;ii[0]++){
for (ii[1]=0;ii[1]<10;ii[1]++){
if (ii[0] == ii[1]) continue;
for (ii[2]=0;ii[2]<10;ii[2]++){
if (ii[0] == ii[2] || ii[1] == ii[2]) continue;
for (ii[3]=0;ii[3]<10;ii[3]++){
if (ii[0] == ii[3] || ii[1] == ii[3] || ii[2] == ii[3]) continue;
for (ii[4]=0;ii[4]<10;ii[4]++){
if (ii[0] == ii[4] || ii[1] == ii[4] || ii[2] == ii[4] || ii[3] == ii[4]) continue;
for (ii[5]=0;ii[5]<10;ii[5]++){
if (ii[0] == ii[5] || ii[1] == ii[5] || ii[2] == ii[5] || ii[3] == ii[5] || ii[4] == ii[5]) continue;
for (ii[6]=0;ii[6]<10;ii[6]++){
if (ii[0] == ii[6] || ii[1] == ii[6] || ii[2] == ii[6]) continue;
if (ii[3] == ii[6] || ii[4] == ii[6] || ii[5] == ii[6]) continue;
for (ii[7]=0;ii[7]<10;ii[7]++){
if (ii[0] == ii[7] || ii[1] == ii[7] || ii[2] == ii[7]) continue;
if (ii[3] == ii[7] || ii[4] == ii[7] || ii[5] == ii[7] || ii[6] == ii[7]) continue;
for (ii[8]=0;ii[8]<10;ii[8]++){
if (ii[0] == ii[8] || ii[1] == ii[8] || ii[2] == ii[8]|| ii[3] == ii[8]) continue;
if (ii[4] == ii[8] || ii[5] == ii[8] || ii[6] == ii[8] || ii[7] == ii[8]) continue;
for (ii[9]=0;ii[9]<10;ii[9]++){
if (ii[0] == ii[9] || ii[1] == ii[9] || ii[2] == ii[9]|| ii[3] == ii[9]) continue;
if (ii[4] == ii[9] || ii[5] == ii[9] || ii[6] == ii[9] || ii[7] == ii[9]|| ii[8] == ii[9]) continue;
for (j=0;j<4;j++) {
d[j] = 0;
for (i=0;i<len[j];i++) {
d[j] = d[j] + ii[id[j][i]] * pow(10,len[j]-i-1);
}; // for i
}; // for j
if (d[3] != 0 && d[0]+d[1]+d[2] == d[3] && ii[id[0][0]] !=0 && ii[id[1][0]] !=0 && ii[id[2][0]] != 0 && ii[id[3][0]] != 0){
printf("%7d\n%7d\n+%6d\n---------------\n%7d\n",d[0],d[1],d[2],d[3]);
exit(0);
};
}
}}}}}}}}};
}
结果:
ABCDE+DFG+DFG=XYZDE
29786
850
+ 850
---------------
31486
ABCDE+DEF+EFG=XYZDE
19385
854
+ 546
----------
20785
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
问题不完整
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
重排一下,对齐明显不对
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用java
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询