Exercise 3-4 Vertical problems
Find all the formulas that are shaped like abc*de (three-digit multiplied by two-digit number) so that in the complete vertical, all numbers belong to a particular set of numbers.
Enter a collection of numbers (no spaces between adjacent numbers) to output all vertical. There should be a number before each vertical, and then there should be a blank line. The total number of final output solutions.
The exact format is shown in sample output (for easy observation, the blank space in the vertical is used instead of the decimal point, but your program should output a space instead of a decimal point).
Example input: 2357
Sample output:
<1>
.. 775
X.. 33
-----
.2325
2325.
-----
25575
The number of solutions = 1
Program 3-4 Vertical Problem
#include <stdio.h>#include<string.h>intMain () {Chars[ -], buf[ -]; //scanf ("%s", s) similar to scanf ("%d", x), will read a string containing no spaces, Tab, carriage returns, into the character array s//note distinguish between scanf ("%s", s) and scanf ("%d", &a[1])//note the distinction between S and &sscanf"%s", s); intABC, DE, D, E, Mul, Dmul, emul, Count =0; for(ABC = -; ABC <=999; Abc++) { for(De =Ten; De <= About; de++) {D= de/Ten; E= de%Ten; Dmul= d *ABC; Emul= e *ABC; Mul= ABC *de; //sprintf () output data to an arraysprintf (BUF,"%d%d%d%d%d", ABC, DE, Dmul, Emul,mul); intOK =1; for(inti =0; I <= strlen (BUF); i++) { //Char *strchr (const char* _str,int _val)//Char *strchr (char* _str,int _ch)//header files: #include <string.h>//function: Finds the first occurrence of the character C in the string s//Description: Returns a pointer to the position of the first occurrence of C, the address returned is the first pointer to the same character as Val at the beginning of the lookup string pointer, and returns NULL if there is no C in S. //return Value: Success returns the position to find the first occurrence of the character, failure returns null if(STRCHR (S, buf[i]) = =NULL) {OK=0; Break; } } if(OK) {printf ("<%d>\n", ++count); //can also be divided into 7 lines of output, more intuitiveprintf"%5d\nx%4d\n-----\n%5d\n%4d \ n-----\n%5d\n\n", ABC, DE, Dmul, Emul, Mul); }}} printf ("The number of solutions =%d", count);}
For sprintf (), STRCHR () function, details Baidu encyclopedia.
3.2 Character Array