竖式问题

来源:互联网 发布:免费男士发型设计软件 编辑:程序博客网 时间:2024/05/28 15:34

B.竖式问题Time Limit: 1000 MSMemory Limit: 32768 KTotal Submit: 1(1 users)Total Accepted: 1(1 users)Special Judge: NoDescription

竖式问题是:有被乘数xyz和乘数ab(xyzab是被乘数和乘数的各位数字),则xyz乘以ab所得的算式:即竖式中的中间结果和最终结果(即乘积)中的数字均为一给定字符串之中的数字。请找出这样的竖式。被乘数、乘数和结果中各位数字可以重复。

Input输入一给定字符串作为竖式问题的限定条件。Output如果找到满足条件的竖式,输出满足条件的竖式数,如果没有满足条件的竖式,输出noneSample 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;}


0 0