求教为什么CE了

P2433 【深基1-2】小学数学 N 合一

compatibility @ 2023-08-31 21:27:16


#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
#include<iostream>
#define π 3.141593
int main() {
    int T = 0;
    scanf("%d", &T);
    if (T == 1) {
        printf("I love Luogu!");
    }
    else if (T == 2) {
        printf("6 4");
    }
    else if (T == 3) {
        int x = 14;
        int y = 4;
        printf("%d\n", x / y);
        printf("%d\n", x - x % y);
        printf("%d\n", x % y);
    }
    else if (T == 4) {
        double x = 500;
        double y = 3;
        printf("%.3lf", x / y);
    }
    else if (T == 5) {
        printf("%d", (220 + 260) / (12 + 20));
    }
    else if (T == 6) {
        float l = 9;
        float w = 6;
        float a = sqrt(l * l + w * w);
        printf("%f", a);
    }
    else if (T == 7) {
        int m = 100;
        printf("%d\n",m+=10 );
        printf("%d\n",m-=20 );
        printf("%d\n",m-m );
    }
    else if (T == 8) {
        float r = 5;
        printf("%f\n",2* π*r);
        printf("%f\n", π*r*r);
        printf("%f\n", (static_cast<double>(4) / 3) * π * r * r * r);
    }
    else if (T == 9) {
        int n = 1;
        for (int i = 0; i < 3; i++)
        {
            n += 1;
            n *= 2;
        }
        printf("%d", n);
    }
    else if (T == 10) {
        printf("9");
    }
    else if (T == 11) {
        double a = 100;
        double b = 3;
        double x = a / b;
        printf("%lf", x);
    }
    else if (T == 12) {
        printf("%d\n", 'M' - 'A'+1);
        printf("%c\n", 'A' + 17);
    }
    else if (T == 13) {
        float r1 = 4;
        float r2 = 10;
        float v = ((4 / 3) * π * r1 * r1 * r1) + ((4 / 3) * π * r2 * r2 * r2);
        float a1 = pow(v, 1.0 / 3);
        int a = a1;
        printf("%d", a);
    }
    else if (T == 14) {//(110 - x)* (10 + x) = 3500;-x^2+100x+1100=3500;-x^2+100x-2400=0;
        float a = -1;
        float b = 100;
        float c = -2400;
        float d = b * b - 4 * a * c;
        float x1 = (-b - sqrt(d)) / (2 * a);
        int x = x1;
        printf("%d", x);

    }
    return 0;
}

by Null_h @ 2023-08-31 21:29:29

把π换一个,它识别不了


by InversionShadow @ 2023-08-31 21:29:42

不能用 π 这个符号吧


by Null_h @ 2023-08-31 21:31:08

像这样(不过还是WA)


#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
#include<iostream>
#define p 3.141593
int main() {
    int T = 0;
    scanf("%d", &T);
    if (T == 1) {
        printf("I love Luogu!");
    }
    else if (T == 2) {
        printf("6 4");
    }
    else if (T == 3) {
        int x = 14;
        int y = 4;
        printf("%d\n", x / y);
        printf("%d\n", x - x % y);
        printf("%d\n", x % y);
    }
    else if (T == 4) {
        double x = 500;
        double y = 3;
        printf("%.3lf", x / y);
    }
    else if (T == 5) {
        printf("%d", (220 + 260) / (12 + 20));
    }
    else if (T == 6) {
        float l = 9;
        float w = 6;
        float a = sqrt(l * l + w * w);
        printf("%f", a);
    }
    else if (T == 7) {
        int m = 100;
        printf("%d\n",m+=10 );
        printf("%d\n",m-=20 );
        printf("%d\n",m-m );
    }
    else if (T == 8) {
        float r = 5;
        printf("%f\n",2*p*r);
        printf("%f\n", p*r*r);
        printf("%f\n", (static_cast<double>(4) / 3) * p * r * r * r);
    }
    else if (T == 9) {
        int n = 1;
        for (int i = 0; i < 3; i++)
        {
            n += 1;
            n *= 2;
        }
        printf("%d", n);
    }
    else if (T == 10) {
        printf("9");
    }
    else if (T == 11) {
        double a = 100;
        double b = 3;
        double x = a / b;
        printf("%lf", x);
    }
    else if (T == 12) {
        printf("%d\n", 'M' - 'A'+1);
        printf("%c\n", 'A' + 17);
    }
    else if (T == 13) {
        float r1 = 4;
        float r2 = 10;
        float v = ((4 / 3) * p * r1 * r1 * r1) + ((4 / 3) * p * r2 * r2 * r2);
        float a1 = pow(v, 1.0 / 3);
        int a = a1;
        printf("%d", a);
    }
    else if (T == 14) {//(110 - x)* (10 + x) = 3500;-x^2+100x+1100=3500;-x^2+100x-2400=0;
        float a = -1;
        float b = 100;
        float c = -2400;
        float d = b * b - 4 * a * c;
        float x1 = (-b - sqrt(d)) / (2 * a);
        int x = x1;
        printf("%d", x);

    }
    return 0;
}

by hdkghc @ 2023-08-31 21:39:37

@compatibility π 不能作为一个宏、变量的名字。


by hdkghc @ 2023-08-31 21:42:11

可以用系统的宏

#define _CRT_SECURE_NO_WARNINGS 1
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<math.h>
#include<iostream>
int main() {
    int T = 0;
    scanf("%d", &T);
    if (T == 1) {
        printf("I love Luogu!");
    }
    else if (T == 2) {
        printf("6 4");
    }
    else if (T == 3) {
        int x = 14;
        int y = 4;
        printf("%d\n", x / y);
        printf("%d\n", x - x % y);
        printf("%d\n", x % y);
    }
    else if (T == 4) {
        double x = 500;
        double y = 3;
        printf("%.3lf", x / y);
    }
    else if (T == 5) {
        printf("%d", (220 + 260) / (12 + 20));
    }
    else if (T == 6) {
        float l = 9;
        float w = 6;
        float a = sqrt(l * l + w * w);
        printf("%f", a);
    }
    else if (T == 7) {
        int m = 100;
        printf("%d\n",m+=10 );
        printf("%d\n",m-=20 );
        printf("%d\n",m-m );
    }
    else if (T == 8) {
        float r = 5;
        printf("%f\n",2* M_PI*r);
        printf("%f\n", M_PI*r*r);
        printf("%f\n", (static_cast<double>(4) / 3) * M_PI * r * r * r);
    }
    else if (T == 9) {
        int n = 1;
        for (int i = 0; i < 3; i++)
        {
            n += 1;
            n *= 2;
        }
        printf("%d", n);
    }
    else if (T == 10) {
        printf("9");
    }
    else if (T == 11) {
        double a = 100;
        double b = 3;
        double x = a / b;
        printf("%lf", x);
    }
    else if (T == 12) {
        printf("%d\n", 'M' - 'A'+1);
        printf("%c\n", 'A' + 17);
    }
    else if (T == 13) {
        float r1 = 4;
        float r2 = 10;
        float v = ((4 / 3) * M_PI * r1 * r1 * r1) + ((4 / 3) * M_PI * r2 * r2 * r2);
        float a1 = pow(v, 1.0 / 3);
        int a = a1;
        printf("%d", a);
    }
    else if (T == 14) {//(110 - x)* (10 + x) = 3500;-x^2+100x+1100=3500;-x^2+100x-2400=0;
        float a = -1;
        float b = 100;
        float c = -2400;
        float d = b * b - 4 * a * c;
        float x1 = (-b - sqrt(d)) / (2 * a);
        int x = x1;
        printf("%d", x);

    }
    return 0;
}

by compatibility @ 2023-09-01 23:03:56

好的,我再看看,感谢


by compatibility @ 2023-09-02 00:22:34

@kdqs8218 为什么最后一题还是WA啊?我在VS上输出的是40啊,难道答案不是40?那我错在哪里了?(还有第14题里为什么sqrt(d)是负数啊,开完根应该是个正数吧?求大佬解答。)


#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
#include<iostream>
#define rou 3.141593
int main() {
    int T = 0;
    scanf("%d", &T);
    if (T == 1) {
        printf("I love Luogu!");
    }
    else if (T == 2) {
        printf("6 4");
    }
    else if (T == 3) {
        int x = 14;
        int y = 4;
        printf("%d\n", x / y);
        printf("%d\n", x - x % y);
        printf("%d\n", x % y);
    }
    else if (T == 4) {
        double x = 500;
        double y = 3;
        printf("%.3lf", x / y);
    }
    else if (T == 5) {
        printf("%d", (220 + 260) / (12 + 20));
    }
    else if (T == 6) {
        float l = 9;
        float w = 6;
        float a = sqrt(l * l + w * w);
        printf("%.4f", a);
    }
    else if (T == 7) {
        int m = 100;
        printf("%d\n",m+=10 );
        printf("%d\n",m-=20 );
        printf("%d\n",m-m );
    }
    else if (T == 8) {
        float r = 5;
        printf("%.4f\n",2* rou*r);
        printf("%.4f\n", rou*r*r);
        printf("%.3f\n", (4.0/3) * rou * r * r * r);
    }
    else if (T == 9) {
        int n = 1;
        for (int i = 0; i < 3; i++)
        {
            n += 1;
            n *= 2;
        }
        printf("%d", n);
    }
    else if (T == 10) {
        printf("9");
    }
    else if (T == 11) {
        double a = 100;
        double b = 3;
        double x = a / b;
        printf("%.4lf", x);
    }
    else if (T == 12) {
        printf("%d\n", 'M' - 'A'+1);
        printf("%c\n", 'A' + 17);
    }
    else if (T == 13) {
        float r1 = 4;
        float r2 = 10;
        float v = ((4.0/3) * rou * r1 * r1 * r1) + ((4.0/3) * rou * r2 * r2 * r2);
        float a1 = pow(v, 1.0 / 3);
        int a = a1;
        printf("%d", a);
    }
    else if (T == 14) {
        double a = -1;
        double b = 100;
        double c = -2400;
        double d = b * b - 4 * a * c;
        double x1 = (-b + sqrt(d)) / (2 * a);
        int x = x1;
        if (x1 - x >= 0.5)
        {
            x += 1;
        }
        printf("%d", x);

    }
    return 0;
}

by Null_h @ 2023-09-02 10:44:27

@compatibility ...显然,答案是50(小学数学哦)


by compatibility @ 2023-09-02 12:57:47

@kdqs8218 啊?不是-x²+100x-2400=0解方程吗?一个根是40一个根是60啊


by Null_h @ 2023-09-02 12:59:27

对啊,你设的是降价,他问的是定价


| 下一页