PAT Level B-Threesome

Title description The
child said: "If you are a threesome, there must be my teacher. Choose the good one and follow it, and the bad one will change it."

In this question, the relationship of the abilities of A, B, and C is given as:

  • A’s ability value is determined to be 2 positive integers;
  • Replacing the two digits of A’s ability value is the B’s ability value;
  • The ability difference between A and B is X times that of C;
  • B's ability value is Y times that of C.

Please point out who is stronger than you should "take it", who is weaker than you should "change it."

Input format
Input three numbers in one line, in order: M (your own ability value), X and Y. All three numbers are positive integers not exceeding 1000.

Output format
First output the ability value of A in a line, and then output the relationship between A, B, C and you in sequence:

  • If it is stronger than you, output Cong;
  • Equality is output Ping;
  • If you are weaker than you, output Gai.

They are separated by 1 space, and there must be no extra spaces at the beginning and end of the line.

Note: If the solution is not unique, the largest solution of A shall prevail; if the solution does not exist, the output will be output No Solution.

Input example 1
48 3 7

Sample output 1
48 Ping Cong Gai

Input example 2
48 11 6

Output sample 2
No Solution


测试点4: The ability value of C may be a floating point number;

Solution
Enumeration:

#include <iostream>
#include <algorithm>
using namespace std;

int M, X, Y;

void print(double x)
{
    
    
    if(x > M) cout << " Cong";
    else if(x == M) cout << " Ping";
    else cout << " Gai";
}

int main()
{
    
    
	cin >> M >> X >> Y;
	
	for (int i = 99; i >= 10; i --)
	{
    
    
	    int a = i;
	    int b = a % 10 * 10 + a / 10;
        double c = (double)abs(a - b) / X;
        
        if(b == c * Y)
        {
    
    
            cout << a;
            print(a), print(b), print(c);
            return 0;
        }
	}
	
	cout << "No Solution" << endl;
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_46239370/article/details/113933355