洛谷刷题记录(python)【入门2】分支结构

2022/1/12 20:33:41

本文主要是介绍洛谷刷题记录(python)【入门2】分支结构,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

【入门2】分支结构https://www.luogu.com.cn/training/101#problemsP5710 【深基3.例2】数的性质

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

if (b == 1) and (a != 1):
    c = 1
else:
    c = 0

print(a, b, c, d)

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

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

P5712 【深基3.例4】Apples.

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

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

n = int(input())

bt = 5 * n
lt = 11 + 3 * n

if bt < lt:
    print("Local")
else:
    print("Luogu")

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

m, h = map(float, input().split())
bmi = float(m / h / h)
if bmi < 18.5:
    print("Underweight")
elif bmi >= 18.5 and bmi < 24:
    print("Normal")
else:
    print("%.6g"%bmi)
    print("Overweight")

P5715 【深基3.例8】三位数排序

a = [int(i) for i in input().split()]
a.sort()
for i in range(2):
    print(a[i], end=' ')
print(a[2])

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

def check(n):
    ans = 0
    if n % 4 == 0:
        if n % 100 == 0:
            if n % 400 == 0:
                ans = 1
        else:
            ans = 1
    return ans

year, mon = map(int, input().split())
rn = [31,29,31,30,31,30,31,31,30,31,30,31]
fn = [31,28,31,30,31,30,31,31,30,31,30,31]
if check(year) == 1:
    print(rn[mon-1])
else:
    print(fn[mon-1])

P1085 [NOIP2004 普及组] 不高兴的津津

a = []
for i in range(7):
    x, y = map(int, input().split())
    a.append(x+y)
maxx = 8
day = 0
for i in range(7):
    if(maxx < a[i]):
        maxx = a[i]
        day = i+1
print(day)

P1909 [NOIP2016 普及组] 买铅笔

n = int(input())

ans = 9999999999999
for i in range(3):
    x, y = map(int, input().split())
    cnt = int(n // x)
    if n % x != 0:
        cnt += 1
    ans = min(ans, cnt * y)
print(ans)

P1055 [NOIP2008 普及组] ISBN 号码

import sys

s = input().strip()
num = []
ls = len(s)
for i in range(ls-1):
    if s[i] >= '0' and s[i] <='9':
        num.append(eval(s[i]))

sum = int(0)
l = len(num)

for i in range(l):
    sum += (i+1) * num[i]

sum %= 11

if(s[ls-1] == 'X' and sum == 10):
    print("Right")
    sys.exit(0)

#if s[ls-1] == 'X'
if str(sum) == s[ls-1]:
    print("Right")
else:
    t = s[0:ls-1]
    if sum == 10:
        t += 'X'
    else:
        t += str(sum)
    print(t)

P1422 小玉家的电费

n = int(input())
if n <= 150:
    sum = n * 0.4463
elif n > 150 and n <= 400:
    sum = 150 * 0.4463 + (n - 150) * 0.4663
else:
    sum = 150 * 0.4463 + 250 * 0.4663 + (n - 400) * 0.5663
print("%.1f"%sum)

P1424 小鱼的航程(改进版)

a, n = map(int, input().split())
cnt = int(n // 7)
ans = cnt * (250 * 5)
x = n % 7
if a == 6:
    if x > 2:
        ans += (x - 2) * 250
elif a == 7:
    if x == 1:
        ans += 0
    elif x > 1 and x < 6:
        ans += (x - 1) *250
    elif x == 6:
        ans += 5 * 250
else:
    if x != 0:
        if a + x == 6:
            ans += x * 250
        elif a + x == 7:
            ans += (x - 1) * 250
        elif a + x > 7:
            ans += (x - 2) * 250
        else:
            ans += x * 250
print(ans)

P1888 三角函数

import math

a = [int(i) for i in input().split()]
a.sort()
x = math.gcd(a[0], a[2])
print(int(a[0]/x), end='')
print("/", end="")
print(int(a[2]/x), end="")

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

a = [int(i) for i in input().split()]
h = int(input())
h += 30
cnt = 0
for i in a:
    if(h >= i):
        cnt += 1
print(cnt)

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

a = [int(i) for i in input().split()]
a.sort()

if a[0] + a[1] <= a[2] | a[2] - a[1] >= a[0]:
    print("Not triangle")
elif a[0] * a[0] + a[1] * a[1] == a[2] * a[2]:
    print("Right triangle")
    if a[0] == a[1]:
        print("Isosceles triangle")
elif a[0] * a[0] + a[1] * a[1] > a[2] * a[2]:
    print("Acute triangle")
    if a[0] == a[1]:
        print("Isosceles triangle")
        if a[1] == a[2]:
            print("Equilateral triangle")
else:
    print("Obtuse triangle")
    if a[0] == a[1]:
        print("Isosceles triangle")

P4414 [COCI2006-2007#2] ABC

a = [int(i) for i in input().split()]
s = input().strip()
a.sort()
if s[0] == 'A':
    if s[1] == 'B':
        print("%d %d %d"%(a[0], a[1], a[2]))
    else:
        print("%d %d %d"%(a[0], a[2], a[1]))
elif s[0] == 'B':
    if s[1] == 'A':
        print("%d %d %d" % (a[1], a[0], a[2]))
    else:
        print("%d %d %d" % (a[1], a[2], a[0]))
else:
    if s[1] == 'A':
        print("%d %d %d"%(a[2], a[0], a[1]))
    else:
        print("%d %d %d"%(a[2], a[1], a[0]))



这篇关于洛谷刷题记录(python)【入门2】分支结构的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程