改了很久还是0分,请问问题在哪?

B2065 鸡尾酒疗法

firecat @ 2024-02-05 21:38:29

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    double x,y;
    cin>>x>>y;
    for(int m=1;m<n;m++){
        double a,b,c,d;
        cin>>a>>b;
        c=a/b;
        d=x/y;
        if(c-d>0.05) {
            cout<<"better";
        } else if(c-d<-0.05) {
            cout<<"worse";
        } else {
            cout<<"same";
        }
    }
    return 0;
}

by cyx012113 @ 2024-02-05 21:50:28

@lyh20090818

#include <iostream>
using namespace std;

struct S
{
    int a, b;
    double d;
    void set() {
        d = (double)(b) / (double)(a) * 100.0;
    }
}a[22];

int main() {
    int n;
    cin >> n;
    for (int i = 1;i <= n;i++) {
        cin >> a[i].a >> a[i].b;
        a[i].set();
        if (i > 1) {
            if (a[i].d - a[1].d > 5) {
                cout << "better" << endl;
            }
            else if (a[1].d - a[i].d > 5) {
                cout << "worse" << endl;
            }
            else cout << "same" << endl;
        }
    }
    return 0;
}

祝你 AK IOI


|