Files
python/C++课程/习题训练/竖式问题.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

28 lines
768 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}