python苹果和虫子_noi寒假刷题之旅_ 1.4编程基础之逻辑表达式与条件分支(21题)

01:判断数正负

#include

#include

using namespace std;

int main()

{

int n;

cin>>n;

if(n>0)

{

cout<

}

else if(n<0)

{

cout<

}

else

{

cout<

}

}

02:输出绝对值

#include

#include

using namespace std;

int main()

{

float n;

cin>>n;

printf("%.2f",fabs(n));

}

03:奇偶数判断

#include

#include

using namespace std;

int main()

{

int n;

cin>>n;

if(n%2)

{

cout<

}

else

{

cout<

}

}

04:奇偶ASCII值判断

#include

using namespace std;

int main()

{

char n;

n=getchar();

if((int)n%2)

{

cout<

}

else

{

cout<

}

}

/*

WA了两发才反应过来cin不能读空格

*/

05:整数大小比较

#include

using namespace std;

int main()

{

int x,y;

cin>>x>>y;

if(x

{

cout<

}

else if(x>y)

{

cout<";

}

else

{

cout<

}

}

06:判断是否为两位数

#include

using namespace std;

int main()

{

int a;

cin>>a;

if(10<=a&&a<=99)

{

cout<<1;

}

else

{

cout<<0;

}

}

07:收集瓶盖赢大奖

#include

using namespace std;

int main()

{

int a,b;

cin>>a>>b;

if(a>=10||b>=20)

{

cout<<1;

}

else

{

cout<<0;

}

}

08:判断一个数能否同时被3和5整除

#include

using namespace std;

int main()

{

double a;

cin>>a;

if(!((long long)a%15))

{

cout<

}

else

{

cout<

}

}

09:判断能否被3,5,7整除

#include

using namespace std;

int main()

{

double a;

cin>>a;

if(!((long long)a%105))

{

cout<

}

else if(!((long long)a%15))

{

cout<

}

else if(!((long long)a%21))

{

cout<

}

else if(!((long long)a%35))

{

cout<

}else if(!((long long)a%3))

{

cout<<3;

}

else if(!((long long)a%5))

{

cout<<5;

}

else if(!((long long)a%7))

{

cout<<7;

}

else

{

cout<

}

}

10:有一门课不及格的学生

#include

using namespace std;

int main()

{

int a,b;

cin>>a>>b;

if((a<60||b<60)&&!(a<60&&b<60))

{

cout<<1;

}

else

{

cout<<0;

}

}

11:晶晶赴约会

#include

using namespace std;

int main()

{

int a;

cin>>a;

if(a==1||a==3||a==5)

{

cout<

}

else

{

cout<

}

}

12:骑车与走路

#include

using namespace std;

int main()

{

double a,b,c;

cin>>a;

b=27+23+a/3.0;

c=a/1.2;

if(b

{

cout<

}

else if(b>c)

{

cout<

}

else

{

cout<

}

return 0;

}

13:分段函数

#include

#include

using namespace std;

int main()

{

double x,y;

cin>>x;

if(0

{

y=-1*x+2.5;

}

else if(5

{

y=2-1.5*(x-3)*(x-3);

}

else

{

y=x/2-1.5;

}

printf("%.3f",y);

return 0;

}

14:计算邮资

#include

#include

using namespace std;

int main()

{

int x,s=8;

char y;

cin>>x>>y;

if(x>1000)

{

s+=(x-1000)/500*4;

if((x-1000)%500)

{

s+=4;

}

}

if(y=='y')s+=5;

cout<

return 0;

}

15:最大数输出

#include

#include

using namespace std;

int main()

{

int a,b,c;

cin>>a>>b>>c;

if(a>=b&&a>=c)

{

cout<

}

if(b>=a&&b>=c)

{

cout<

}

if(c>=b&&c>=a)

{

cout<

}

return 0;

}

16:三角形判断

#include

#include

using namespace std;

int main()

{

int a,b,c;

cin>>a>>b>>c;

int max=a>b? a:b;

max=max>c ? max:c;

int min=a

min=min

int mid;

if(max==a&&min==c||max==c&&min==a)mid=b;

if(max==b&&min==a||max==a&&min==b)mid=c;

if(max==b&&min==c||max==c&&min==b)mid=a;

if(min+mid>max&&max-min

{

cout<

}

else

{

cout<

}

return 0;

}

17:判断闰年

#include

#include

using namespace std;

int main()

{

int a;

cin>>a;

if((a%4==0)&&(a%100))

{

cout<

}

else if(a%400==0)

{

cout<

}

else

{

cout<

}

return 0;

}

/*数据范围没到3200,所以不用考虑这个*/

18:点和正方形的关系

#include

#include

using namespace std;

int main()

{

double x,y;

cin>>x>>y;

if(fabs(x)>1||fabs(y)>1)

{

cout<

}

else

{

cout<

}

return 0;

}

19:简单计算器

#include

#include

using namespace std;

int main()

{

int x,y,z;

char opt;

cin>>x>>y>>opt;

switch(opt)

{

case '+':

{

cout<

break;

}

case '-':

{

cout<

break;

}

case '*':

{

cout<

break;

}

case '/':

{

if(y==0)

{

cout<

}

else

{

cout<

}

break;

}

default:

cout<

}

return 0;

}

20:求一元二次方程的根

#include

#include

using namespace std;

void function(double &a)

{

if(fabs(a)<1e-4)a=0;

}

int main()

{

double a,b,c;

cin>>a>>b>>c;

double temp=b*b-4*a*c;

if(temp<0)

{

double sb = -b / (2*a), xb = sqrt(4*a*c-b*b) / (2*a);

function(sb);

function(xb);

if(xb>0)

{

printf("x1=%.5lf+%.5lfi;x2=%.5lf-%.5lfi",sb,xb,sb,xb);

}

else

{

printf("x1=%.5lf+%.5lfi;x2=%.5lf-%.5lfi",sb,-xb,sb,-xb);

}

}

else if(temp>0)

{

double x1 = (-b + sqrt(b*b-4*a*c))/(2*a), x2 = (-b-sqrt(b*b-4*a*c))/(2*a);

double max=x1>x2 ?x1:x2;

double min=x1

function(max);

function(min);

printf("x1=%.5lf;x2=%.5lf",max,min);

}

else

{

double x1 = (-b + sqrt(b*b-4*a*c))/(2*a), x2 = (-b-sqrt(b*b-4*a*c))/(2*a);

function(x1);

printf("x1=x2=%.5lf",x1);

}

return 0;

}

21:苹果和虫子2

#include

using namespace std;

int main()

{

long long n,x,y,z;

cin>>n>>x>>y;

if(x)

{

if(y%x)

{

z=n-1-y/x;

}

else

{

z=n-y/x;

}

}

else

{

z=0;

}

if(z<0)z=0;

cout<

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值