B.竖式问题 | |||||
| |||||
Description | |||||
竖式问题是:有被乘数xyz和乘数ab(xyzab是被乘数和乘数的各位数字),则xyz乘以ab所得的算式:即竖式中的中间结果和最终结果(即乘积)中的数字均为一给定字符串之中的数字。请找出这样的竖式。被乘数、乘数和结果中各位数字可以重复。 | |||||
Input | |||||
输入一给定字符串作为竖式问题的限定条件。 | |||||
Output | |||||
如果找到满足条件的竖式,输出满足条件的竖式数,如果没有满足条件的竖式,输出none | |||||
Sample Input | |||||
12 3456 345678
| |||||
Sample Output | |||||
The number of solutions = 1 none. The number of solutions = 15
|
#include <stdio.h>
#include <string.h>
int main()
{
int abc, de, x, y, z, i, ok, count;
char s[20], buff[100];
while(~scanf("%s", s))
{
count = 0;
for (abc = 100; abc < 999; abc++)
{
for (de = 10; de < 99; de++)
{
x = abc * (de % 10);
y = abc * (de / 10);
z = abc * de;
sprintf(buff, "%d%d%d%d%d", abc, de, x, y, z);
ok = 1;
for (i = 0; i < strlen(buff); i++)
if (strchr(s, buff[i]) == NULL)
ok = 0;
if (ok)
{
++count;
// printf("%5d/nX%4d/n-----/n%5d/n%4d/n-----/n%5d/n", abc, de, x, y, z);
}
}
}
if(count == 0)
printf("none.\n");
else
printf("The number of solutions = %d\n", count);
}
return 0;
}