求助!(玄关)

B2065 鸡尾酒疗法

C_Boa @ 2024-06-09 11:00:23

为啥不对?

#include<iostream>
using namespace std;
int n;
double x,y,a,b;
int main(){
    cin>>n>>x>>y;
    double a=x/y;
    for(int i=2;i<=n;i++){
        cin>>x>>y;
        double b=x/y;
        if(a-b>=0.05) cout<<"worse"<<endl;
        else if(b-a>=0.05) cout<<"better"<<endl;
        else cout<<"same"<<endl;
    }
    return 0;
}

这红题太抽象了


by OIer_Hhy @ 2024-06-09 11:14:48

@C_Boa

x/y 错了,应改为 y/x

#include<iostream>
using namespace std;
int n;
double x,y;
int main(){
    cin>>n>>x>>y;
    double a=y/x;
    for(int i=2;i<=n;i++){
        cin>>x>>y;
        double b=y/x;
        if((a-b)>0.05) cout<<"worse"<<endl;
        else if((b-a)>0.05) cout<<"better"<<endl;
        else cout<<"same"<<endl;
    }
    return 0;
}

by C_Boa @ 2024-06-09 11:17:50

@LALaker 感谢大佬!


|