竖式问题

来源:互联网 发布:linux dd bs count 编辑:程序博客网 时间:2024/05/22 10:46
#include<stdio.h>#include<string.h>int main(){    int count=0;    //计数    char s[20]; //存储输入的字符串。    char buf[99];   //存储合并后的字符串。    printf("请输入字符串s:\n");    scanf("%s",s);    int x,y,z;    for(int abc=111;abc<=999;abc++)    {        for(int de=11;de<=99;de++)        {            x=abc*(de%10);  //乘个位的结果            y=abc*(de/10);  //乘十位的结果            z=abc*de;   //三位数乘两位数的结果            sprintf(buf,"%d%d%d%d%d",abc,de,x,y,z);//输出字符串(合并字符串)            int ok=1;   //标志位ok设置为1            for(int i=0;i<strlen(buf);i++)//获得buf的实际长度            {                if(strchr(s,buf[i])==NULL)//在字符串s中查找buf[i]字符。                {                    ok=0;   //如果找不到就将标志位设置为0                }            }            if(ok)//满足竖式问题的条件            {                count++;                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;}

这里写图片描述
这里写图片描述

0 0
原创粉丝点击