Program 3-4 vertical issues

Vertical problem. Identify all shaped like abc * de (two digits multiplied by three digits) of the equation, such that in the full vertical, all numbers belong to a specific set of numbers. Digital input set (no spaces between adjacent digital), all vertical outputs. Before each number should be vertical, then there should be a blank line. Total output of the final solution. The specific format, see sample output (for ease of viewing vertical spaces in the display to switch to the decimal point, but your program should output spaces, rather than a decimal point).

Sample input: 2357

Sample output:

<1>

..775

X..33

-----

.2325

2325.

-----

25575

The number of solutions = 1

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

printf, sprintf and fprintf usage distinction
 
1.printf is associated and the standard output file (stdout) of, fprintf is not the limit.
 
2.fprintf is a file operation
 
3.sprintf is formatted output to a string, fprintf It is a formatted output stream, typically to a file
 

strchr functional capabilities as the first place to find a match in a given character string. Function prototype: char * strchr (const char * str, int c), i.e., a first search character C appears (an unsigned char) in the first position of the string pointed to by the argument str. strchr function is included in the C standard library <string.h> in.

 

 

Released seven original articles · won praise 0 · Views 109

Guess you like

Origin blog.csdn.net/qq_44954571/article/details/103979389