六、分支语句的综合应用-习题

六十六、水仙花数

image

#include <iostream>
using namespace std;
int main(){
  int n,a,b,c;
  cin>>n;
  c=n%10;
  b=n/10%10;
  a=n/100%10;
  if((a*a*a)+(b*b*b)+(c*c*c)==n) cout<<"YES";
  else cout<<"NO";
  return 0;
}

六十七、完全平方数

image

#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int n,x;
  cin>>n;
  x=sqrt(n);
  if(x*x==n) cout<<"yes";
  else cout<<"no";
  return 0;
}

六十八、三数中最大和最小

image

#include <iostream>
using namespace std;
int main(){
  int a,b,c,max,min;
  cin>>a>>b>>c;
  max=(a>b)?a:b;
  min=(a<b)?a:b;
  max=(max>c)?max:c;
  min=(min<c)?min:c;
  cout<<"The maximum number is : "<<max<<endl;
  cout<<"The minimum number is : "<<min;
  return 0;
}

六十九、某年某月有几天

image

#include <iostream>
using namespace std;
int main(){
  int y,m;
  cin>>y>>m;
  if(m==1||m==3||m==5||m==7||m==8||m==10||m==12) cout<<31;
  else if(m==4||m==6||m==9||m==11) cout<<30;
  else if(y%4==0 && y%100!=0 || y%400==0) cout<<29;
  else cout<<28;
  return 0;
}

七十、骑车与走路

image

#include <iostream>
using namespace std;
int main(){
  int jl;
  double bx,qc;
  cin>>jl;
  bx=jl/1.2;
  qc=27+(jl/3.0)+23;
  if(qc<bx) cout<<"Bike";
  else if(qc==bx) cout<<"All";
  else cout<<"Walk";
  return 0;
}

七十一、分西瓜

image

#include <iostream>
using namespace std;
int main(){
  int weight;
  cin>>weight;
  if(weight==2) cout<<"NO, you can't divide the watermelon into two even parts.";
  else if(weight%2==0) cout<<"YES, you can divide the watermelon into two even parts.";
  else cout<<"NO, you can't divide the watermelon into two even parts.";
  return 0;
}

七十二、游客

image

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  int M;
  cin>>M;
  if(M<=30) cout<<fixed<<setprecision(2)<<M*0.2;
  else if(M>30 && M<=60) cout<<fixed<<setprecision(2)<<30*0.2+(M-30)*0.6;
  else cout<<"NO";
  return 0;
}

七十三、计算邮资

image

#include <iostream>
using namespace std;
int main(){
  int n,fy;
  char c;
  cin>>n>>c;
  if(n<=1000) fy=8;
  else if(n>1000) {
    fy=8+((n-1000)/500)*4;
    if((n-1000)%500!=0){
      fy+=4;
    }
  }

  if(c=='y'){
    fy=fy+5;
  }

  cout<<fy;
  return 0;
}

七十四、鱼大大跑步

image

#include <iostream>
using namespace std;
int main(){
  int m,s,sj;
  cin>>m>>s;
  sj=s+m*60;
  if(sj<180) cout<<"S";
  else if(sj>=180 && sj<200) cout<<"A";
  else if(sj>=200 && sj<220) cout<<"B";
  else if(sj>=220 && sj<240) cout<<"C";
  else if(sj>=240 && sj<300) cout<<"D";
  else if(sj>=300) cout<<"E";
  return 0;
}

七十五、大数的平方

image

#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  cout<<max(a,b)*max(a,b);
  return 0;
}

七十六、上什么课

image

#include <iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n==1) cout<<"swim";
  else if(n==3) cout<<"program";
  else if(n==5) cout<<"read";
  else if(n==6) cout<<"math";
  else cout<<"rest";
  return 0;
}

七十七、睡个好觉

image

#include <iostream>
using namespace std;
int main(){
  int kss,ksf,jss,jsf,ydds,yddf,ks,js,ydd;
  cin>>kss>>ksf;
  cin>>jss>>jsf;
  cin>>ydds>>yddf;
  ks=kss*60+ksf;
  js=jss*60+jsf;
  ydd=ydds*60+yddf;
  if(ydd>=ks&&ydd<=js){
    cout<<"GG";
  }else{
    cout<<"Nice";
  }
  return 0;
}

七十八、求首位

image

#include <iostream>
using namespace std;
int main(){
  int a;
  cin>>a;
  if(a>=1000 && a<10000){
    cout<<a/1000;
  }else if(a>=100 && a<1000){
    cout<<a/100;
  }else{
    cout<<a/10000;
  }
  return 0;
}

七十九、成绩等级

image

#include <iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n==100) cout<<"S";
  else if(n>=90 && n<100) cout<<"A";
  else if(n>=80 && n<90) cout<<"B";
  else if(n>=70 && n<80) cout<<"C";
  else if(n>=60 && n<70) cout<<"D";
  else cout<<"E";
  return 0;
}
posted @ 2025-09-05 23:02  jch123456  阅读(19)  评论(0)    收藏  举报