You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
741 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<bits/stdc++.h>
using namespace std;
int main()
{
int i, ok, abc, de, x, y, z, count = 0;
char s[11], buf[50];
scanf("%s", s);
for(abc = 111; abc <= 999; abc++)
for(de = 11; de <= 99; de++)
{
x = abc*(de%10); y = abc*(de/10); z = abc*de;
sprintf(buf, "%d%d%d%d%d", abc, de, x, y, z);//将产生的所有数字存入缓冲区。
ok = 1;
for(i = 0; i<strlen(buf) && ok==1; i++)
if(strchr(s, buf[i]) == NULL) ok = 0;//将缓冲区的每一个数字与输入的数字序列比较若不存在则strchr返回NULL。
if(ok)//若经计算产生的数字均合法,则输出竖式。
{
printf("<%d>\n", ++count);
printf("%5d\nX%4d\n-----\n%5d\n%4d\n-----\n%5d\n\n", abc, de, x, y, z);
}
}
printf("The number of solutions = %d\n", count);
return 0;
}