C语言中的cout是什么?听取蛙声WA一片qaqaaaaaa

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

Yaoyanni @ 2023-08-24 10:17:57

6,8,9,11,12,13,14过不了

#include <stdio.h>
#include <math.h>
int main() {
    int A=0;
    scanf("%d",&A);
    if (A == 1) {
       printf("I love Luogu!");
    } else if (A == 2) {
       printf("6 4");
    } else if (A == 3) {
        int d=14,e=4;
        printf("%d\n%d\n%d\n",d/e,d/e*4,d%e);
    } else if (A == 4) {
        double f=500,g=3,h;
        h=f/g;
        printf("%.6g",h);
    } else if (A == 5) {
        int k;
        k=480/32;
        printf("%d",k);
    } else if (A == 6) {
        int l;
        l=sqrt(6*6+9*9);
        printf("%d",l);
    } else if (A == 7) {
        int m,n;
        m=110;
        n=90;
        printf("%d\n%d\n0\n",m,n);
    } else if (A == 8) {
        double p,q,r,s=3.141593;
        p=2*s*5;
        q=5*5*s;
        r=5*5*5*s*4/3;
        printf("%lf\n%lf\n%lf\n",p,q,r);
    } else if (A == 9) {
        printf("26");
    } else if (A== 10) {
         printf("9");  
    } else if (A== 11) {
        double x;
        x=100/(8-5);
        printf("%lf",x);
    } else if (A == 12) {
        printf("13\n""r"); 
    } else if (A == 13) {
        double y,s=3.141593;
        y=4/3*s*(4*4*4+10*10*10);
        printf("%lf",y);
    } else if (A == 14) {
        int price=110,people=10;
        double sum;
        sum=price*people;
        while(sum<3500){
            price--;
            people++;
        }
        if(sum>=3500){
            sum=round(sum*10000);
            printf("%.4g",price*people);
        }
    }
    return 0;
}

by wdd2929 @ 2023-08-24 10:22:57

cout是c++的啊


by FurippuWRY @ 2023-08-24 10:23:44

@Yaoyanni cout是输出。


by wdd2929 @ 2023-08-24 10:24:15

有些题要舍去小数点后得数字,格式化输出%d就行了


by FurippuWRY @ 2023-08-24 10:25:01

比如输出Hello,world,就写成std::cout<<"Hello,world";


by wdd2929 @ 2023-08-24 10:27:00

@FurippuWRY 新人不太懂,直接让ta声明命名空间罢()


by lcx666_76 @ 2023-08-24 10:31:22

qp


by FurippuWRY @ 2023-08-24 10:31:53

那就先写上using namespace std;


by FurippuWRY @ 2023-08-24 10:33:21

举个例子

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"Hello World";
   return 0;
}

或者写成

#include<bits/stdc++.h>
int main(){
    std::cout<<"Hello World";
   return 0;
}

by FurippuWRY @ 2023-08-24 10:34:49

@Yaoyanni cout比printf会慢些,所以尽量在主函数的开头加上

    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);

by FurippuWRY @ 2023-08-24 10:36:05

@Yaoyanni 如果有帮助就给个关注吧谢谢喵!


| 下一页