Vertical problem
Topic:
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).
Sample Input:
2357
Sample Output:
<1>
.. 775
X.. 33
-----
.2325
2325.
-----
25575
The number of solutions = 1
1#include <stdio.h>2#include <string.h>3 intMain ()4 {5 Chars[ -],buf[ about];//used to accept input number strings6 intA,b,c,count =0;7scanf"%s", s);//Note the address is not required here &8 for(intI=111; i<=999; I++)//Traverse all three-digit numbers9 {Ten for(intj= one; j<= about; j + +)//Traverse all the two-digit numbers one { aA = i* (j%Ten);//the multiplier above -b = i* (j/Ten);//the following multiplier -c = i*j;//Results the //to determine whether or not to meet the requirements -sprintf (buf,"%d%d%d%d%d", i,j,a,b,c);//put an integer number into a character array buf - //Easy to Judge - intOK =1; + for(intk=0; K<strlen (buf); k++) - if(STRCHR (s,buf[k]) ==null) OK =0; + if(ok) a { atcount++; -printf"<%d>\n", Count); -printf"%5d\nx%4d\n-----\n%5d\n%4d\n-----\n%5d\n", i,j,a,b,c); - } - } - } inprintf"The number of the solutions =%d", Count); - return 0; to}
Description
- In c, a string is actually an array of characters--you can handle a string like a normal array--just pay attention to the use of input and output and string functions.
- STRCHR to find a single character in a string
function Prototypes : extern char *strchr (char *str,char character)
parameter description:str is a pointer to a string, character is a pending character.
Library Name: #include <string.h>
function Function: Find the first occurrence position of character character from the string str.
return description: Returns a pointer to the position of the first occurrence of the character character, or null if not found.
3. printf output to screen, FPRINGF output to file, sprintf output to string
4. strings can only be strcpy (a, b), strcmp (a, b), strcat (a, b) to perform "assignment", "compare" and "join operations", which are declared in String.h
Vertical problem--skillfully using character array