最近在看刘汝佳的这本紫书,看到这个竖式问题,有点不太明白,就是循环的初始条件为什么是111和11,不是100和10呢?
下边贴上源码:
#include
#include
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;
}
友情链接:
©Copyright © 2022 2006年世界杯歌曲_冰岛世界杯排名 - guoyunzhan.com All Rights Reserved.