Smoke Big OJ-2509
Description
When he was in elementary school, Xiaoming often invented his own new algorithm. Once, the teacher's topic is:
1/4 Times 8/5.
Xiaoming actually put together the numerator, the denominator stitching together, the answer is: 18/45
The teacher was just trying to criticize him, and then he thought, the answer happened.
For the numerator and denominator are all one-digit numbers in the 1~9, what other formulas can be computed like this?
Please write down the number of all the different formulas (including examples in the question).
Obviously, after the numerator's denominator, for example: 4/1 times 5/8 is satisfying, this is a different formula.
But for the same numerator denominator, 2/2 times 3/3 has too many types, not counting!
Please output all the fractional combinations that satisfy the Ming algorithm and the number of such fractional combinations.
Input
No input
Output
Please output all the fractional combinations that satisfy the Ming algorithm and the number of such fractional combinations.
Sample Output
1/2 5/41/4 8/51/6 4/31/6 6/4...9/4 8/9
CODE
1#include <iostream>2#include <cmath>3 using namespacestd;4 Const Doubleeps=10e-Ten;5 intMain ()6 {7 inti,j,k,l;8 intnum=0;9 for(i=1;i<Ten; i++)Ten for(k=1;k<Ten; k++) One for(j=1;j<Ten; j + +) A for(l=1;l<Ten; l++) - { - if(i = = k | | j = l)Continue; the //if ((i/j*k/l) = = ((i*10+j)/(k*10+l) ) - if(Fabs (i*Ten+ j) *1.0/(k*Ten+L)-(i*j*1.0)/(K*l)) <EPS) - { -cout<<i<<'/'<<k<<' '<<j<<'/'<<l<<Endl; +num++; - } + } Acout<<num<<Endl; at return 0; - } -
1. Use brute force search when necessary, with a four-cycle.
2. The integral type is quasi, and the floating-point number is approximate.
Determine if two floating-point numbers are equal, "differential" (Fabs (A-B) <= "a certain fraction of the precision") (10E-10)
3. The number of circular layers is more than a long, attention order!
Blue Bridge cup-odd fraction (numerator denominator stitching)