chen_1111 @ 2024-06-08 09:40:53
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m;
double s,d;
cin>>m;
int a[m][2];
for(int i=0;i<m;i++)
{
for(int j=0;j<2;j++)
{
cin>>a[i][j];
}
}
s=a[0][0]*100/a[0][1];
for(int i=1;i<m;i++)
{
d=a[i][0]*100/a[i][1];
if(s-d>5)
cout<<"worse";
else if(d-s>5)
cout<<"better";
else
cout<<"same";
}
return 0;
}
by lkrkerry @ 2024-06-08 09:53:59
你的s=....行无论如何都会得到整数,这样会导致精度损失
by tangyiqi @ 2024-08-12 10:35:33
@123A123
用我的AC代码吧
#include <iostream>
using namespace std;
int main(){
int x,y,n;
cin>>n;
cin>>x>>y;
double v = y*1.0/x;
for(int i = 0;i<n-1;i++){
cin>>x>>y;
double temp = y*1.0/x;
if(v-temp>0.05) cout<<"worse"<<endl;
else if(temp-v>0.05) cout<<"better"<<endl;
else cout<<"same"<<endl;
}
return 0;
}
求关,谢谢