0 求助 必关

B2065 鸡尾酒疗法

michaelwanghaoyu @ 2024-10-26 22:15:46

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int dyz;
    for (int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        if (i==0)
        {
            dyz=1.0*y/x;
            cout<<"same"<<endl;
            continue;
        }
        if (1.0*y/x-dyz>=0.05)
        {
            cout<<"better"<<endl;
        }
        else if (dyz-1.0*y/x>=0.05) 
        {
            cout<<"worse"<<endl;
        }
        else
        {
            cout<<"same"<<endl;
        }
    }
}

by Laihaocheng @ 2024-10-26 22:17:46

#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int arr[n][2];
    int i=0,j=0,k=1;
    double m=0,p=0;
    while(i<n){
        while(j<2){
            cin >> arr[i][j];
            j++;
        }
        j=0;
        i++;
    }
    m=arr[0][1]*(1.0)/arr[0][0];
    while(k<n){
        p=arr[k][1]*(1.0)/arr[k][0];
        if(p-m > 0.05){
            cout << "better" << endl;
        }
        if(p-m < -0.05){
            cout << "worse" << endl;
        }
        if(p-m < 0.05&&p-m > -0.05){
            cout << "same" << endl;
        }
        k++;
    }
    return 0;
}

by shawn0618 @ 2024-10-26 22:18:40

你得dyz是个int啊


by shawn0618 @ 2024-10-26 22:22:58

@michaelwanghaoyu

long long n,p,r;
    cin>>n;
    cin>>p>>r;
    double v=r*1.0/p,tmp;
    for (int i=0;i<n-1;i++){
        cin>>p>>r;
        tmp=r*1.0/p;
        if (v-tmp>0.05)  cout<<"worse"<<endl;
        else if (tmp-v>0.05)  cout<<"better"<<endl;
        else cout<<"same"<<endl;
    }

这么写,你的代码中

if (1.0*y/x-dyz>=0.05)//把等号去掉
        {
            cout<<"better"<<endl;
        }
        else if (dyz-1.0*y/x>=0.05) //把等号去掉
        {
            cout<<"worse"<<endl;
        }

你代码里等号太多了


by michaelwanghaoyu @ 2024-10-26 22:25:03

@shawn0618 关注了


|