为什么打不出worse不懂哪里错了

B2065 鸡尾酒疗法

ONicklgzh @ 2023-11-09 19:53:01

#include <stdio.h>
int main(){
    int n,i;
    double eff1,eff2;
    double a[50],b[50];
    scanf("%d",&n);
    scanf("%lf",&a[1],&b[1]);
    for(i=2;i<=n;i++){
        scanf("%lf %lf\n",&a[i],&b[i]);
        eff1=b[1]/a[1];
        eff2=b[i]/a[i];
        if(eff2-eff1>=0.05){
            printf("better");}
            else if(eff1-eff2>=0.05){
                printf("worse");}
            else {
            printf("same");}
    }
        return 0;
    }

by penguin_is_cool @ 2023-11-09 19:56:51

@ONicklgzh AC代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,sum=5.0;
    cin>>n;
    double a[n],b[n];
    cin>>a[0]>>b[0];
    a[0]=b[0]/a[0]*100.0;
    for (int i=1;i<n;i++){
        cin>>a[i]>>b[i];
        a[i]=b[i]/a[i]*100;
    }
    for (int i=1;i<n;i++){
        if (a[i]>a[0]-5 and a[i]<a[0]-5) cout<<"same\n";
        else if (a[i]>a[0]+sum) cout<<"better\n";
        else if (a[i]<a[0]-sum) cout<<"worse\n";
        else cout<<"same\n";
    }
}

by penguin_is_cool @ 2023-11-09 19:57:22

@ONicklgzh 你搞的有一点复杂了


by ONicklgzh @ 2023-11-09 21:14:30

@penguin_is_cool 有没有c语言的解法啊 没学过c++


by penguin_is_cool @ 2023-11-09 22:16:24

@ONicklgzh 哦我只学过c++,但c++其实跟c语言差不多,所以可以试一下。


|