请求增强数据
查看原帖
请求增强数据
384214
esquigybcu楼主2021/3/7 08:26

RT。

错误代码(提交100pts):

#include <stdio.h>

typedef long long ll;

int main()
{
    ll a = 0, b = 0; //方程化为ax+b=0
    ll side = 1, sign = 1, num = 0; // 左侧side=1,
    char c = getchar(), x;
    while (true)
    {
        if ('a' <= c && c <= 'z')
        {
        	x = c;
        	if(a==0) a=1;
        }
            
        else if ('0' <= c && c <= '9')
        {
            while ('0' <= c && c <= '9')
            {
                num = num * 10 + c - '0';
                c = getchar();
            }
            if ('a' <= c && c <= 'z')
            {
                a += num * side * sign;
                x = c;
            }
            else
            {
                b += num * side * sign;
            }
            num = 0;
            sign = 1;
            continue;
        }
        else if (c == '+')
        {
            sign = 1;
        }
        else if (c == '-')
        {
            sign = -1;
        }
        else if (c == '=')
        {
            side = -1;
        }
        else
        {
            break;
        }
        
        c = getchar();
    }
    double ans = -((double)b)/a;
    // printf("a=%d,b=%d\n",a,b);
    // if (ans <= 0) ans = 
    if (ans>-.0005f && ans<0.0005f) 
    {
        printf("%c=0.000",x);
        return 0;
    }
    printf("%c=%.3lf", x, -((double)b)/a);
    return 0;
}

hack input:4=a

output:a=-4.000

2021/3/7 08:26
加载中...