算法入门竞赛:竖式问题

来源:互联网 发布:layer子域名挖掘机 编辑:程序博客网 时间:2024/05/22 05:11

最近在看刘汝佳的这本紫书,看到这个竖式问题,有点不太明白,就是循环的初始条件为什么是111和11,不是100和10呢?

下边贴上源码:

#include <stdio.h>#include <string.h> int main(){int count = 0;char s[20], buf[99];scanf("%s", s);for (int abc = 111; abc <= 999; abc++)//为什么是111? {for (int de = 11; de <= 99; de++) //为什么是11? {int x = abc * (de % 10);int y = abc * (de / 10);int z = abc * de;sprintf(buf, "%d%d%d%d%d", abc, de, x, y, z);int ok = 1;for (int i = 0; i < strlen(buf); i++){if (strchr(s, buf[i]) == NULL)ok = 0;}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;} 


阅读全文
1 0
原创粉丝点击