wa声一片 暴力拆的解不了

B2065 鸡尾酒疗法

Czh116489 @ 2022-09-13 09:56:58

#include<stdio.h>
int main()
{
    int n,x,y;
    int sample1=0,a=0,good=0,sample;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {

        if(i==1)
        {
            scanf("%d %d",&sample1,&a);
            x=a/sample1;

        }
        else
        {
            scanf("%d %d",&sample,&good);
            y=good/sample;
            if(y-x>0.05)
            puts("well");
            else if(x-y>0.05)
            puts("worse");
            else
            puts("same");
        }
    }

    return 0;
}

by Czh116489 @ 2022-09-13 09:58:16

那里better也不行。。。打错了


by Superficiall @ 2022-09-13 10:23:40

@Czh116489 小数

 x=a/sample1;
 x=a*1.0/sample1;

试一下,数据类型换double吧


by Superficiall @ 2022-09-13 10:25:18

@Czh116489 还有这句

y=good/sample;
y=good*1.0/sample;

by Superficiall @ 2022-09-13 10:28:09

@Czh116489 帮你改了一下,AC了

#include<stdio.h>
int main()
{
    double n,x,y;
    double sample1=0,a=0,good=0,sample;
    scanf("%lf",&n);
    for(int i=1;i<=n;i++)
    {

        if(i==1)
        {
            scanf("%lf %lf",&sample1,&a);
            x=a*1.0/sample1;

        }
        else
        {
            scanf("%lf %lf",&sample,&good);
            y=good*1.0/sample;
            if(y-x>0.05)
            puts("better");
            else if(x-y>0.05)
            puts("worse");
            else
            puts("same");
        }
    }

    return 0;
}

by Czh116489 @ 2022-09-13 10:33:32

@Superficiall 哦哦怪不得之前改了double过不了原来少了小数 感谢


by Superficiall @ 2022-09-13 10:35:47

@Czh116489 不客气(^▽^)


|