没注意到的地方
丙的能力值有可能是小数。(测试点4)
实现
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int cmp(double a, double b)
{
if (a > b)
return 0;
else if (a == b)
return 1;
else
return 2;
}
int main()
{
string strJ, strY;
string out[3] = { "Cong","Ping","Gai" };
int jia, yi, M, X, Y, i;
double bing=0; //丙可能是小数
cin >> M >> X >> Y;
for (i = 99; i >= 10; i--)
{
jia = i;
strJ = to_string(jia);
strY = strJ;
reverse(strY.begin(), strY.end());
yi = atoi(strY.c_str());
int cha = abs(jia - yi);
if (cha*1.0 / X == yi*1.0 / Y)
{
bing = cha*1.0 / X; break;
}
}
if(bing)
cout << jia << " " << out[cmp(jia, M)] << " " << out[cmp(yi, M)] << " " << out[cmp(bing, M)] << endl;
if (!bing)
cout << "No Solution" << endl;
return 0;
}