头像

宇智波-止水




离线:1天前


活动打卡代码 AcWing 712. 正数

#include<bits/stdc++.h>
using namespace std;
int main(void){
    int s=0;
    for(int i=0;i<=6;i++){
        double a;
        cin>>a;
        if(a>0) s++;
    }
    cout<<s<<" positive numbers";
}            


活动打卡代码 AcWing 709. 奇数

#include<bits/stdc++.h>
using namespace std;
int main(void){
    int x;
    cin>>x;
    for(int i=1;i<=x;i++){
        if(i%2!=0) cout<<i<<endl;  
    }
}            


活动打卡代码 AcWing 708. 偶数

#include<bits/stdc++.h>
using namespace std;
int main(void){
    for(int i=1;i<=100;i++){
        if(i%2==0) cout<<i<<endl;  
    }
}            


活动打卡代码 AcWing 661. 平均数3

#include<bits/stdc++.h>
using namespace std;
int main(void){

    double a,b,c,d,x,y,z;
    cin>>a>>b>>c>>d>>y;

    x=(a*2+b*3+c*4+d*1)/10;
    z=(x+y)/2;

    printf("Media: %.1lf\n",x);

    if(x>=7) cout<<"Aluno aprovado."<<endl;

    else if(x<5) cout<<"Aluno reprovado."<<endl;

    else if(x>=5&&x<7){
        cout<<"Aluno em exame."<<endl;

        printf("Nota do exame: %.1lf\n",y);

        if(z>=5) cout<<"Aluno aprovado."<<endl;
        else cout<<"Aluno reprovado."<<endl;

        printf("Media final: %.1lf", z);
    }
}   



求大佬指教!!!

题目链接 平均数3

问题:明明在DEVC++编译器上运行是对的,但是提交上去却是错的!QQ图片20210222173012.png

错误的代码:

#include<bits/stdc++.h>//万能头
using namespace std;
int main(void){//不用写“return 0”
    cin.tie(0);//代码优化
    ios::sync_with_stdio(false);//代码优化

    double a,b,c,d,x,y,z;
    cin>>a>>b>>c>>d>>y;

    x=(a*2+b*3+c*4+d*1)/10;
    z=(x+y)/2;

    printf("Media: %.1lf\n",x);

    if(x>=7) cout<<"Aluno aprovado."<<endl;

    if(x<5) cout<<"Aluno reprovado."<<endl;

    if(x>=5&&x<7){
        cout<<"Aluno em exame."<<endl;

        printf("Nota do exame: %.1lf\n",y);

        if(z>=5) cout<<"Aluno aprovado."<<endl;
        else cout<<"Aluno reprovado."<<endl;

        cout<<"Media final: "<<z<<endl;
    }
}                  

然后就WA了

错误点:

输入:

6.2 6.2 8.4 8.3

DEVC++编译器输出:

Media: 7.3
Aluno aprovado.

提交上去输出:

Aluno aprovado.
Media: 7.3

标准答案:

Media: 7.3
Aluno aprovado.

谢谢大佬!!!




#include<bits/stdc++.h>
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a,b,c;
    cin>>a>>b>>c;
    if(b*b-4*a*c<0||a==0) cout<<"Impossivel calcular";
    else printf("R1 = %.5lf\nR2 = %.5lf\n",(-b+sqrt(b*b-4*a*c))/(2*a),(-b-sqrt(b*b-4*a*c))/(2*a));
}  


活动打卡代码 AcWing 663. 简单排序

#include<bits/stdc++.h>
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if(a<b&&b<c) cout<<a<<endl<<b<<endl<<c;
    if(a<c&&c<b) cout<<a<<endl<<c<<endl<<b;
    if(b<a&&a<c) cout<<b<<endl<<a<<endl<<c;
    if(b<c&&c<a) cout<<b<<endl<<c<<endl<<a;
    if(c<a&&a<b) cout<<c<<endl<<a<<endl<<b;
    if(c<b&&b<a) cout<<c<<endl<<b<<endl<<a;
    cout<<endl<<endl;
    cout<<a<<endl<<b<<endl<<c;
}


活动打卡代码 AcWing 672. 税

#include<bits/stdc++.h>
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a;
    cin>>a;
    if(a>=0&&a<=2000) cout<<"Isento";
    if(a>2000&&a<=3000) printf("R$ %.2lf",(a-2000)*0.08);
    if(a>3000&&a<=4500) printf("R$ %.2lf",(a-3000)*0.18+80);
    if(a>4500) printf("R$ %.2lf",(a-4500)*0.28+350);
}



思路:算出总分钟数相减再模

#include<bits/stdc++.h>//万能头
using namespace std;
int main(void){//不用加“return 0”
    cin.tie(0);//代码优化
    ios::sync_with_stdio(false);//代码优化
    int a1,b1,a2,b2,n,m,x,y;
    cin>>a1>>b1>>a2>>b2;
    n=a1*60+b1;
    m=a2*60+b2;
    if(n>=m) m+=24*60;
    x=(m-n)/60;
    y=(m-n)%60;
    cout<<"O JOGO DUROU "<<x<<" HORA(S) E "<<y<<" MINUTO(S)";
} 

谢谢大家,点个赞再走呗



活动打卡代码 AcWing 668. 游戏时间2

#include<bits/stdc++.h>
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a1,b1,a2,b2,n,m,x,y;
    cin>>a1>>b1>>a2>>b2;
    n=a1*60+b1;
    m=a2*60+b2;
    if(n>=m) m+=24*60;
    x=(m-n)/60;
    y=(m-n)%60;
    cout<<"O JOGO DUROU "<<x<<" HORA(S) E "<<y<<" MINUTO(S)";
}