PAT (Basic Level) Practice (中文) 1088 三人行 (20分)

1.题目

子曰:“三人行,必有我师焉。择其善者而从之,其不善者而改之。”

本题给定甲、乙、丙三个人的能力值关系为:甲的能力值确定是 2 位正整数;把甲的能力值的 2 个数字调换位置就是乙的能力值;甲乙两人能力差是丙的能力值的 X 倍;乙的能力值是丙的 Y 倍。请你指出谁比你强应“从之”,谁比你弱应“改之”。

输入格式:

输入在一行中给出三个数,依次为:M(你自己的能力值)、X 和 Y。三个数字均为不超过 1000 的正整数。

输出格式:

在一行中首先输出甲的能力值,随后依次输出甲、乙、丙三人与你的关系:如果其比你强,输出 Cong;平等则输出 Ping;比你弱则输出 Gai。其间以 1 个空格分隔,行首尾不得有多余空格。

注意:如果解不唯一,则以甲的最大解为准进行判断;如果解不存在,则输出 No Solution

输入样例 1:

48 3 7

输出样例 1:

48 Ping Cong Gai

输入样例 2:

48 11 6

输出样例 2:

No Solution

2.题目分析

丙可能为浮点数

3.代码

#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int m, x, y;
	int list[2] = {0};
	string temp;
	cin >> m >> x >> y;
	for (int i = 99; i >= 10; i--)
	{
		list[0] = i;
		temp = to_string(i);
		reverse(temp.begin(), temp.end());
		list[1] = atoi(temp.c_str());
		if (y*abs(list[0]-list[1]) == x*list[1])
			break;
	}
	//list[2] = list[1] / y;
	if (list[0] == 10) { cout << "No Solution" << endl; return 0; }
	cout << list[0];
	for (int i = 0; i < 2; i++)
	{
		if (list[i] == m)cout << ' ' << "Ping";
		else if (list[i] > m)cout << ' ' << "Cong";
		else cout << ' ' << "Gai";
	}
	double bing = (double)list[1] / y;
	if (bing == m)cout << ' ' << "Ping";
	else if (bing > m)cout << ' ' << "Cong";
	else cout << ' ' << "Gai";
		
}

 

posted @ 2020-03-08 21:50  Jason66661010  阅读(143)  评论(0)    收藏  举报