丙的能力值可能是小数,需使用double型存储
正确代码
#include<iostream>
using namespace std;
void print(int me, double other) {
if(other > me) cout << " Cong";
else if(other == me) cout << " Ping";
else cout << " Gai";
return ;
}
int main() {
int m, x, y;
double a3;
cin >> m >> x >> y;
for(int i = 98; i >= 10; i--) {
int left = i, right = i % 10 * 10 + i / 10;
if(y * abs(left - right) == x * right) {
cout << left;
a3 = 1.0 * right / y;
print(m, left);
print(m, right);
print(m, a3);
return 0;
}
}
cout << "No Solution";
return 0;
}
文章评论