为什么编译失败啊

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

SZ2528 @ 2020-05-10 21:15:30

RT

代码:

#include<bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin>>n;
    switch(n) {
        case 1:
            cout<<"I love Luogu!"<<endl;
            break;
        case 2:
            cout<<2+4<<" "<<10-2-4<<endl;
            break;
        case 3:
            cout<<int(14/4)<<" "<<" "<<14-int(14/4)*4<<endl;
            break;
        case 4:
            printf("%.3lf",500.0/3);
            break;
        case 5:
            cout<<(260+220)/(12+20)<<endl;
            break;
        case 6:
            cout<<sqrt(6*6+9*9)<<endl;
            break;
        case 7:
            cout<<100+10<<" "<<100+10-20<<" "<<0<<endl;
            break;
        case 8:
            cout<<5*1.0*2*3.141593<<" "<<3.141593*5*5<<" "<<4.0/3*3.141593*3*3*3<<endl;
            break;
        case 9:
            int n=4,peach=1;
            for(int i=0; i<n-1; i++) {
                peach++;
                peach*=2;
            }
            cout<<peach<<endl;
            break;
        case 10:
            cout<<9<<endl;
            break;
        case 11:
            cout<<100*1.0/(5+8)<<endl;
            break;
        case 12:
            cout<<int('M'-'A'+1)<<endl<<char('A'-1+18)<<endl;
            break;
        case 13:
            cout<<pow((4.0/3*3.141593*4*4*4)+(4.0/3*3.141593*10*10*10),1.0/3)<<endl;
            break;
        case 14:
            cout<<50<<endl;
            break;
    }
    return 0;
}

by zhjxaoini @ 2020-05-10 21:24:46

@AKIOI官方账号 啊这个我知道,我只是说变量重名没事……


by AKIOI官方账号 @ 2020-05-10 21:26:17

@zhaojinxi right


by zhjxaoini @ 2020-05-10 21:26:29

@MOJANG 有 bits/stdc++.h 就行了啊


by KaguyaH @ 2020-05-10 21:26:42

……能不能定义变量和 switch 无关吧……


by AKIOI官方账号 @ 2020-05-10 21:26:51

最好加一个cmath


by TensorFlow_js @ 2020-05-10 21:26:52

case{ } 就这样行


by iMya_nlgau @ 2020-05-10 21:27:49

@SZ棋 把 case 9 里面的语句用大括号括上就好了


by TensorFlow_js @ 2020-05-10 21:27:50

@zhaojinxi 你计算有错......3,7,10,11WA


by KaguyaH @ 2020-05-10 21:27:50

下面这段代码也能通过编译:

signed int main() {
    {
        signed int n;
        cin >> n;
        cout << n << endl;
    }
    {
        long long n = -1LL;
        cout << n << endl;
    }
    return 0;
}

by zhjxaoini @ 2020-05-10 21:28:10

@AKIOI官方账号 不是有 bits/stdc++.h 了吗……


上一页 | 下一页