各位大佬,为啥20分?样例都过了QAQ

B2065 鸡尾酒疗法

Urbosa @ 2024-09-20 20:03:00

回帖必关!!!

#include <bits/stdc++.h>
using namespace std;
long double n, x, y, a, b;

int main() {
    cin >> n;
    for (long long i = 1; i <= n; i++) {
        cin >> a >> b;
        if (i == 1) {
            x = b / a;
        }
        if (i > 1) {
            y = b / a;
            if (y - x > 0.05) {
                cout << "better\n";
            }if (x - y > 0.05) {
                cout << "worse\n";
            } else {
                cout << "same\n";
            }
        }
    }
    return 0;
}
有啥问题吗* 0 *

by a11223344 @ 2024-09-20 20:11:17

第二个if加个else


by Yxy7952 @ 2024-09-20 20:11:33

@Urbosa


#include <bits/stdc++.h>
using namespace std;
long double n, x, y, a, b;

int main() {
    cin >> n;
    cin >> a >> b;
    x = b / a;
    for (long long i = 1; i < n; i++) {
        cin >> a >> b;
        y = b / a;
        if (y - x > 0.05) {
            cout << "better\n";
        }
        else if (x - y > 0.05) {
            cout << "worse\n";
        } else {
            cout << "same\n";
        }
    }
    return 0;
}

``

by a11223344 @ 2024-09-20 20:11:43

第二个if前加个else


by a11223344 @ 2024-09-20 20:12:13

#include <bits/stdc++.h>
using namespace std;
long double n, x, y, a, b;

int main() {
    cin >> n;
    for (long long i = 1; i <= n; i++) {
        cin >> a >> b;
        if (i == 1) {
            x = b / a;
        }
        if (i > 1) {
            y = b / a;
            if (y - x > 0.05) {
                cout << "better\n";
            }else if (x - y > 0.05) {
                cout << "worse\n";
            } else {
                cout << "same\n";
            }
        }
    }
    return 0;
}

|