题目:找出所有形如abc*de(三位数乘以两位数)的算式,使得在完整的竖式中,多有数字都属于一个特定的数值集合。
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char s[20], buf[99];
int abc, de, x, y, z;
scanf("%s",s);
// abc = 234;
// de = 11;
int i;
for(abc = 100; abc <= 999; abc++)
{
for(de = 10; de <= 99; de++)
{
x = abc * (de%10);
y = abc * (de/10);
z = abc * de;
sprintf(buf, "%d%d%d%d%d", x, y, z, abc, de);
int ok = 1;
for(i = 0; i < strlen(buf); i++)
if(strchr(s, buf[i]) == NULL) ok = 0;
if(ok == 1)
{
printf("%5d\nX%4d\n-----\n%5d\n%4d\n-----\n%5d", abc, de, x, y, z);
}
}
}
// printf("%s",buf);
return 0;
}