洛谷题单python解【入门2】分支结构

  • P2433 【深基1-2】小学数学 N 合一
import math
n=int(input())     
if n==1:
    print('I love Luogu!')
elif n==2:
    print(2+4,10-2-4)
elif n==3:
    print(14//4)
    print(14-14%4)
    print(14%4)
elif n==4:
    print("%.3f"%(500/3))
elif n==5:
    print((260+220)//(12+20))
elif n==6:
    print("%.4f"%(math.sqrt(6**2+9**2)))
elif n==7:
    print(100+10)
    print(100+10-20)
    print(0)
elif n==8:
    pi=3.141593
    r=5
    print("%.4f"%(2*pi*r))
    print("%.4f"%(pi*r*r))
    print("%.3f"%((4*pi*(r**3))/3))
elif n==9:
    day4=1
    day3=(day4+1)*2
    day2=(day3+1)*2
    day1=(day2+1)*2
    print(day1)
elif n==10:
    y=(8*30-10*6)/24
    x=10*6-y*6
    print(int((x+y*10)/10))
elif n==11:
    print("%.4f"%(100/(8-5)))
elif n==12:
    print(ord('M')-64)
    print(chr(64+18))
elif n==13:
    pi=3.141593
    print(int(pow((4*pi*(4**3+10**3))/3,1/3)))
elif n==14:
    money=1 
    price=110
    num=10
    x=[]
    while money!=0:
        money=price*num
        if money==3500:
            x.append(price)
        price-=1
        num+=1
    mprice=min(x)
    print(mprice)

  • P5709 【深基2.习6】Apples Prologue / 苹果和虫子

import math
m,t,s=map(int,input().split())
if t!=0:
    n=math.ceil(s/t)
    a=m-n
    if a<0:
        print("0")
    else:
        print(str(a))
else:
    print("0")

  • P5710 【深基3.例2】数的性质

n=int(input())
if n%2==0 and n>4 and n<=12:
    a=1
    b=1
    c=0
    d=0
elif n%2!=0 and n>4 and n<=12:
    a=0
    b=1
    c=1
    d=0
elif n%2==0 and(n<=4 or n>12):
    a=0
    b=1
    c=1
    d=0
elif n%2!=0 and(n<=4 or n>12):
    a=0
    b=0
    c=0
    d=1

print(a,b,c,d)

  • P5711 【深基3.例3】闰年判断

n=int(input())
if n%100==0:
    if n%400==0:
        leap=1
    else:
        leap=0
else:
    if n%4==0:
        leap=1
    else:
        leap=0
if leap==1:
    print("1")
else:
    print("0")

  • P5712 【深基3.例4】Apples

x=int(input())
if x<=1:
    print("Today, I ate %d apple."%x)
else:
     print("Today, I ate %d apples."%x)

  • P5713 【深基3.例5】洛谷团队系统

n=int(input())
local=n*5
luogu=11+n*3
if local<luogu:
    print("Local")
else:
    print("Luogu")

  • P5714 【深基3.例7】肥胖问题

m,h=map(float,input().split())
bmi=m/h**2
if bmi<18.5:
    print("Underweight")
else:
    if bmi<24:
        print("Normal")
    else:
        bmi_o=format(bmi,'.6g')
        print(str(bmi_o))
        print("Overweight")

  • P5715 【深基3.例8】三位数排序
a,b,c=map(int,input().split())
if a<b and a<c:
    if b<c:
        print(a,b,c)
    else:
        print(a,c,b)

else :
    if b<a and b<c:
        if a<c:
            print(b,a,c)
        else:
            print(b,c,a)
    else:
        if a<b:
            print(c,a,b)
        else:
            print(c,b,a)

  • P5716 【深基3.例9】月份天数

y,m=map(int,input().split())
days=[31,28,31,30,31,30,31,31,30,31,30,31]
if (y%4==0 and y%100!=0) or y%400==0:
    if m==2:
        print('29')
    else:
        print(days[m-1])
else:
    print(days[m-1])

  • P1085 [NOIP2004 普及组] 不高兴的津津
class_time=[]
for i in range(7):
    s,m=map(int,input().split())
    class_time.append(s+m)
max_time=max(class_time)
if max_time<=8:
    print(0)
else:
    day=class_time.index(max_time)
    print(str(day+1))

  • P1909 [NOIP2016 普及组] 买铅笔

from math import ceil
n=int(input())
min_cost=float('inf')
for i in range(3):
    quantity,price=map(int,input().split())
    num=ceil(n/quantity)
    if num*price<=min_cost:
        min_cost=num*price
print(min_cost)

    
    

  • P5717 【深基3.习8】三角形分类

a,b,c=map(int,input().split())    
sides=sorted([a,b,c])
a,b,c=sides
if a+b<=c:
    print("Not triangle")
    exit()//这里卡了好久,一直不通过报Wrong Answer.wrong answer Too many lines.后来加上"exit()"就通过了
elif a**2+b**2==c**2:
    print("Right triangle")
elif a**2+b**2>c**2:
    print("Acute triangle")
elif a**2+b**2<c**2:
    print("Obtuse triangle")
if a==b or b==c:
    print("Isosceles triangle")
if a==b==c:
    print("Equilateral triangle")    

  • P1422 小玉家的电费

n=int(input())
if n<=150:
    electricity_bill=n*0.4463
elif 150<n<=400:
    electricity_bill=150*0.4463+(n-150)*0.4663
else:
    electricity_bill=150*0.4463+250*0.4663+(n-400)*0.5663
electricity_bill=round(electricity_bill,1)
print(electricity_bill)

  • P1424 小鱼的航程(改进版

x,n=map(int,input().split())
total_distance=0
current_day=x
for i in range(n):
    if current_day<6:
        total_distance+=250
    current_day=(current_day%7)+1
print(total_distance)

  • P1888 三角函数

import math
a,b,c=map(int,input().split())
sides=sorted([a,b,c])
a,b,c=sides
d=math.gcd(a,c)
print(str(a//d)+'/'+str(c//d))

  • P1046 [NOIP2005 普及组] 陶陶摘苹果

s=list(map(int,input().split()))
max_height=int(input())
new_height=max_height+30
n=0
for i in range(10):
    if s[i]<=new_height:
        n+=1
print(n)

  • P4414 [COCI2006-2007#2] ABC

numbers=sorted((map(int,input().split())))
s=input().strip()
mapping={'A':numbers[0],'B':numbers[1],'C':numbers[2]}
result=[str(mapping[char]) for char in s]
print(" ".join(result))
  • P1055 [NOIP2008 普及组] ISBN 号码

isbn=input().strip()
digits=isbn.replace('-','')[:-1]
check_number=isbn[-1]
s=0
for i in range(1,10):
    s+=i*int(digits[i-1])
check_calculate=s%11
if check_calculate==10:
    check_calculate="X"
else:
    check_calculate=str(check_calculate)
if check_calculate==check_number:
    print("Right")
else:
    right_isbn=isbn[:-1]+check_calculate
    print(right_isbn)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值