寒假刷题实录-基础语法-02判断语句

第二部分判断语句

020-665倍数

#include<iostream>
#include<cstdio>
#define D 3.14159
using namespace std;
int main(){
   
    int a,b;
    cin>>a>>b;
    if(a%b==0||b%a==0)
        printf("Sao Multiplos\n");
    else
        printf("Nao sao Multiplos\n");
    return 0;
} 

021-660零食

#include<iostream>
#include<cstdio>
#define D 3.14159
using namespace std;
int main(){
    int m,n;
    double price;
    cin>>m>>n;
    if(m==1){
       price=4.00*n; 
    }  
    else if(m==2){
         price=4.50*n; 
    }
    else if(m==3){
        price=5.00*n;
    }
    else if(m==4){
        price=2.00*n;
    }
    else if(m==5){
        price=1.50*n;
    }
    printf("Total: R$ %.2lf",price);    
    return 0;
} 

022-659区间

#include<iostream>
#include<cstdio>
#define D 3.14159
using namespace std;
int main(){
    double m;
    cin>>m;
    if(m>=0&&m<=25){
        printf("Intervalo [0,25]");
    }
    else if(m>25&&m<=50){
        printf("Intervalo (25,50]");
    }
    else if(m>50&&m<=75){
        printf("Intervalo (50,75]");
    }
    else if(m>75&&m<=100){
        printf("Intervalo (75,100]");
    }
    else{
        printf("Fora de intervalo");
    }
    return 0;
} 

023-664三角形

#include<iostream>
#include<cstdio>
#define D 3.14159
using namespace std;
int main(){
    double a,b,c;
    bool triangle=true;
    cin>>a>>b>>c;
    if(a+b<=c)
        triangle=false;
    else if(a+c<=b)
        triangle=false;
    else if(b+c<=a)
        triangle=false;
    if(triangle){
        printf("Perimetro = %.1lf\n",a+b+c);
    }
    else{
        printf("Area = %.1lf",(a+b)*c/2);
    }
    return 0;
}

024-667游戏时间

#include<iostream>
#include<cstdio>
#define D 3.14159
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a==b){
        printf("O JOGO DUROU 24 HORA(S)");
    }
    else if(b<=24&&b>a){
        printf("O JOGO DUROU %d HORA(S)",b-a);
    }
    else if(b<a){
        printf("O JOGO DUROU %d HORA(S)",24-a+b);
    }
    return 0;
}

025-669加薪

#include<iostream>
#include<cstdio>
#define D 3.14159
using namespace std;
int main(){
    double salary,wages;
    cin>>salary;
    wages=salary;
    if(salary>=0.00&&salary<=400.00){
        salary*=1.15;
        printf("Novo salario: %.2lf\n",salary);
        printf("Reajuste ganho: %.2lf\n",wages*0.15);
        printf("Em percentual: %d %%",15);
    }
    else if(salary>=400.01&&salary<=800.00){
        salary*=1.12;
        printf("Novo salario: %.2lf\n",salary);
        printf("Reajuste ganho: %.2lf\n",wages*0.12);
        printf("Em percentual: %d %%\n",12);
    }
    else if(salary>=800.01&&salary<=1200.00){
        salary*=1.10;
        printf("Novo salario: %.2lf\n",salary);
        printf("Reajuste ganho: %.2lf\n",wages*0.10);
        printf("Em percentual: %d %%\n",10);
    }
    else if(salary>=1200.01&&salary<=2000.00){
        salary*=1.07;
        printf("Novo salario: %.2lf\n",salary);
        printf("Reajuste ganho: %.2lf\n",wages*0.07);
        printf("Em percentual: %d %%\n",7);
    }else if(salary>2000){
        salary*=1.04;
        printf("Novo salario: %.2lf\n",salary);
        printf("Reajuste ganho: %.2lf\n",wages*0.04);
        printf("Em percentual: %d %%\n",4);
    }

    return 0;
}

026-670动物

思路:无脑遍历

#include<iostream>
#include<cstdio>
#define D 3.14159
using namespace std;

int main(){
    string a,b,c;
    // scanf("%s%s%s",&a,&b,&c);
    cin>>a>>b>>c;
    if(a=="vertebrado")
    {
        if(b=="ave")
        {
            if(c=="carnivoro")
            {
                printf("aguia");
            }
            else if(c=="onivoro")
            {
                printf("pomba");
            }
        }
        else if(b=="mamifero")
        {
            if(c=="onivoro")
            {
                printf("homem");
            }
            else if(c=="herbivoro")
            {
                printf("vaca");
            }
        }

    }
    if(a=="invertebrado")
    {
        if(b=="inseto")
        {
            if(c=="hematofago")
            {
                printf("pulga");
            }
            else if(c=="herbivoro")
            {
                printf("lagarta");
            }
        }
        else if(b=="anelideo")
        {
            if(c=="hematofago")
            {
                printf("sanguessuga");
            }
            else if(c=="onivoro")
            {
                printf("minhoca");
            }
        }

    }

    return 0;
}

027-657选择练习1

#include<iostream>
using namespace std;
int main ()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
 //   if()
    if(b>c&&d>a&&(c+d)>(a+b)&&a%2==0&&c>0&&d>0)
        cout<<"Valores aceitos";
    else
        cout<<"Valores nao aceitos";
    return 0;
}

028-671DDD

#include<iostream>
using namespace std;
int main ()
{
    int a;
    cin>>a;
    if(a==61)
        cout<<"Brasilia";
    else if(a==71)
        cout<<"Salvador";
    else if(a==11)
        cout<<"Sao Paulo";
    else if(a==21)
        cout<<"Rio de Janeiro";
    else if(a==32)
        cout<<"Juiz de Fora";
    else if(a==19)
        cout<<"Campinas";
    else if(a==27)
        cout<<"Vitoria";
    else if(a==31)
        cout<<"Belo Horizonte";
    else 
        cout<<"DDD nao cadastrado";
    return 0;
}

029-662点的坐标

#include<iostream>
using namespace std;
int main ()
{
    float a,b;
    cin>>a>>b;
    if(a>0&&b>0)
        cout<<"Q1";
    else if(a<0&&b>0)
        cout<<"Q2";
    else if(a<0&&b<0)
        cout<<"Q3";
    else if(a>0&&b<0)
        cout<<"Q4";
    else if(a==0.0&&b==0.0)
        cout<<"Origem";
    else if(a==0)
        cout<<"Eixo Y ";
    else if(b==0)
        cout<<"Eixo X ";      
    return 0;
}

030-666三角型的类型

#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
    int i,j;
    float a[3];
    cin>>a[0]>>a[1]>>a[2];
   for(i=0;i<3;i++)  {
        for(j=i+1;j<3;j++){
            if(a[i]<a[j]){
                float c;
                c=a[i];
                a[i]=a[j];
                a[j]=c;
            }
        }
    }
   // for(i=0;i<3;i++)
    //    cout<<a[i]<<endl;
    if(a[0]>=(a[1]+a[2]))
        cout<<"NAO FORMA TRIANGULO"<<endl;
    else{
        if(pow(a[0],2)==(pow(a[1],2)+pow(a[2],2)))
            cout<<"TRIANGULO RETANGULO"<<endl;
        if(pow(a[0],2)>(pow(a[1],2)+pow(a[2],2)))
            cout<<"TRIANGULO OBTUSANGULO"<<endl;
        if(pow(a[0],2)<(pow(a[1],2)+pow(a[2],2)))
            cout<<"TRIANGULO ACUTANGULO"<<endl;
        if(a[0]==a[1]&&a[0]==a[2]&&a[1]==a[2])
            cout<<"TRIANGULO EQUILATERO"<<endl;
        else if(a[0]==a[1]||a[0]==a[2]||a[2]==a[1])
            cout<<"TRIANGULO ISOSCELES"<<endl;
    }

    return 0;
}

031-668游戏时间2

#include<iostream>
using namespace std;
int main ()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(d>=b&&c>a)
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)",c-a,d-b);
    else if(c>a&&d<b)
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)",c-a-1,60+d-b);
    else if(c<a&&d>=b)
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)",23-a+c,d-b);
    else if(c<a&&d<b)
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)",23-a+c,60+d-b);
    else if(c==a&&d==b)
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)",24,0);
    else if(c==a&&d>b)
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)",0,d-b);
    else if(c==a&&d<b)
        printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)",23,60+d-b);

    return 0;
}

032-672税

#include<iostream>
using namespace std;
int main ()
{
    float a,b;
    cin>>a;
    if(a>=0.00&&a<=2000.00)
        printf("Isento");
    else if(a>=2000.01&&a<=3000.00)
        printf("R$ %.2lf",0.08*(a-2000));
    else if(a>=3000.01&&a<=4500.00)
        printf("R$ %.2lf",((0.08*1000)+(a-3000)*0.18));
    else if(a>=4500.00)
        printf("R$ %.2lf",0.08*1000+0.18*1500+(a-4500)*0.28);
    return 0;
}

033-663简单排序

#include<iostream>
using namespace std;
int main ()
{
    int a[3],b[3],i,j,change;
    cin>>a[0]>>a[1]>>a[2];
    for(i=0;i<3;i++)
    {
        b[i]=a[i];
    }
    for(i=0;i<3;i++)
    {
        for(j=i+1;j<3;j++)
        {
            if(a[i]>a[j])
            {
                change=a[i];
                a[i]=a[j];
                a[j]=change;
            }
        }
    }
    for(i=0;i<3;i++)
    {
        printf("%d\n",a[i]);
    }
    cout<<endl;
    for(i=0;i<3;i++)
    {
        printf("%d\n",b[i]);
    }
    return 0;
}

034-658一元二次方程

#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
    double a,b,c,r1,r2;
    cin>>a>>b>>c;
    if(b*b-4*a*c<0||a==0)
        cout<<"Impossivel calcular";
    else{
        r1=(-1*b+sqrt(b*b-4*a*c))/(2*a);
        r2=(-1*b-sqrt(b*b-4*a*c))/(2*a);
        printf("R1 = %.5lf\n",r1);
        printf("R2 = %.5lf\n",r2);
    }
    return 0;
}

035-661平均数3

#include<iostream>
using namespace std;
int main ()
{
    float a,b,c,d,average,special,compute;
    cin>>a>>b>>c>>d;
    average=(a*2+3*b+4*c+d)/10;

    if(average>=7.0){
        printf("Media: %.1lf\n",average);
        printf("Aluno aprovado.\n");
    }
    else if(average<5.0){
        printf("Media: %.1lf\n",average);
        printf("Aluno reprovado.\n");
    }
    else if(average>=5.0&&average<7.0){

        cin>>special;
        printf("Media: %.1lf\n",average);
        printf("Aluno em exame.\n");
        printf("Nota do exame: %.1lf\n",special);
        compute=(average+special)/2;
        if(compute>=5.0)
            printf("Aluno aprovado.\n");
        else
            printf("Aluno reprovado.\n");
        printf("Media final: %.1lf",compute);

    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值