72分,求助哪里错了

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

Yu09217777 @ 2022-07-19 16:43:05

#include <bits/stdc++.h>
using namespace std;
int main(){
    //有错 72分 
    int q;
    cin >> q;
    if (q == 1){
        cout << "I love Luogu!";
    }else if (q == 2){
        int s,c;
        s = 2 + 4;
        c = 10 - s; 
        cout << s << " " << c;
    }else if (q == 3){
        int m,n,sum;
        m = 14 / 4;
        sum = 4 * m;
        n = 14 % 4;
        cout << m << endl;
        cout << sum << endl;
        cout << n << endl; 
    }else if (q == 4){
        double n;
        n = 500 / 3;
        cout << fixed << setprecision(3) << n;
    }else if (q == 5){
        int t;
        t = (260 + 220) / (12 + 20);
        cout << t;      
    }else if (q == 6){
        cout << sqrt (6 * 6 + 9 * 9);
    }else if (q == 7){
        int a,b,c;
        a = 100 + 10;
        b = a - 20;
        c = 0;
        cout << a << endl;
        cout << b << endl;
        cout << c << endl; 
    }else if (q == 8){
        const double pi = 3.14159;
        cout << pi * 5 * 2 << " " << 5 * 5 * pi << " " << 4 / 3 * pi * 5 * 5 * 5; 
    }else if (q == 9){
        int sum;
        sum = (((1 + 1) * 2 + 1) * 2 + 1) * 2;
        cout << sum;
    }else if (q == 10){
        cout << (15 + 7.5 * 10) / 10;
    }else if (q == 11){
        cout << 100 / (8 - 5);
    }else if (q == 12){
        int m;
        char x;
        m = 'M'- 65 + 1;
        x = 65 + 18 - 1;
        cout << m << endl;
        cout << x << endl;
    }else if (q == 13){
        double y1,y2,sum,pi = 3.14159;
        y1 = 4 * 4 * 4 * 4 / 3 * pi;
        y2 = 10 * 10 * 10 * 4 / 3 * pi;
        sum = y1 + y2;
        cout << pow (sum,1 / 3 * 1.0);
    }else if (q == 14){
        cout << 50;
    }
    return 0;
}

by Yu09217777 @ 2022-07-19 16:45:14

错了4,8,11,13


by 凉蚊子LLL @ 2022-07-19 17:06:16

@Yu09217777

1.很多数据类型有些问题

如:

n = 500 / 3;

程序会先计算500/3=166,再将166转为double类型。 可以改为:

n = 500 / 3.0;

其他位置同理

2.关于#8#13:

取 π=3.141593

3.关于#8:

每行一个数字

附AC代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int q;
    cin >> q;
    if (q == 1){
        cout << "I love Luogu!";
    }else if (q == 2){
        int s,c;
        s = 2 + 4;
        c = 10 - s; 
        cout << s << " " << c;
    }else if (q == 3){
        int m,n,sum;
        m = 14 / 4;
        sum = 4 * m;
        n = 14 % 4;
        cout << m << endl;
        cout << sum << endl;
        cout << n << endl; 
    }else if (q == 4){
        double n;
        n = 500 / 3.0;
        cout << fixed << setprecision(3) << n;//修改
    }else if (q == 5){
        int t;
        t = (260 + 220) / (12 + 20);
        cout << t;      
    }else if (q == 6){
        cout << sqrt (6 * 6 + 9 * 9);
    }else if (q == 7){
        int a,b,c;
        a = 100 + 10;
        b = a - 20;
        c = 0;
        cout << a << endl;
        cout << b << endl;
        cout << c << endl; 
    }else if (q == 8){
        const double pi = 3.141593;//修改
        cout << pi * 5 * 2 << endl << 5 * 5 * pi << endl << 4 / 3.0 * pi * 5 * 5 * 5; //修改
    }else if (q == 9){
        int sum;
        sum = (((1 + 1) * 2 + 1) * 2 + 1) * 2;
        cout << sum;
    }else if (q == 10){
        cout << (15 + 7.5 * 10) / 10;
    }else if (q == 11){
        cout << 100.0 / (8 - 5);//修改
    }else if (q == 12){
        int m;
        char x;
        m = 'M'- 65 + 1;
        x = 65 + 18 - 1;
        cout << m << endl;
        cout << x << endl;
    }else if (q == 13){
        double y1,y2,sum,pi = 3.141593;//修改
        y1 = 4 * 4 * 4 * 4 / 3.0 * pi;//修改
        y2 = 10 * 10 * 10 * 4 / 3.0 * pi;//修改
        sum = y1 + y2;
        cout << (int)pow(sum,1 / 3.0 );//修改
    }else if (q == 14){
        cout << 50;
    }
    return 0;
}

by Yu09217777 @ 2022-07-19 17:18:33

@凉蚊子LLL 终于过了!万分感谢


by Yu09217777 @ 2022-07-19 17:22:28

@凉蚊子LLL 再问大神一个问题:怎么根据测试点错误修改代码,看的我很懵


by 凉蚊子LLL @ 2022-07-19 18:23:59

@Yu09217777

下载数据点(doge


by Yu09217777 @ 2022-07-19 18:59:08

@凉蚊子LLL 这我不会用,额...


by ruanjingqi @ 2022-07-26 12:05:35

@Yu09217777 各个评测状态 AC: Accept,程序通过。 CE: Compile Error,编译错误。 PC: Partially Correct,部分正确。 WA: Wrong Answer,答案错误。 RE: Runtime Error,运行时错误。 TLE: Time Limit Exceeded,超出时间限制。 MLE: Memory Limit Exceeded,超出内存限制。 OLE: Output Limit Exceeded,输出超过限制。 UKE: Unknown Error,出现未知错误。 懂了吗?


by CSP_AK_xyy20110721 @ 2022-07-29 15:32:09

8题π=3.141593,≠3.14159!!!


by CSP_AK_xyy20110721 @ 2022-07-29 15:33:47

@Yu09217777 @ruanjingqi 本题第几个点就是第几题


by Yu09217777 @ 2022-09-03 20:44:25

谢谢各位大佬指教


| 下一页