【python】牛客竞赛语法入门班顺序结构习题 python解法

题目链接:牛客竞赛语法入门班顺序结构习题_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ

目录

1001 这是一道签到题

1002 排列式

1003 小飞机

1004 学姐的"Helloworld"

1005 乘法表

1006 KiKi学程序设计基础

1007 疫情死亡率

1008 爱因斯坦的名言

1009 字符串输出1.0

1010 牛牛学说话之-整数

1011 牛牛学说话之-浮点数

1012 牛牛学加法

1013 牛牛学除法

1014 牛牛学取余

1015 浮点除法

1016 计算带余除法

1017 水题再次来袭:明天是星期几?

1018 开学?

1019 helloworld

1020 a+b

1021 整数的个位

1022 整数的十位

1023 反向输出一个四位数

1024 总成绩和平均分计算

1025 计算平均成绩

1026 牛牛学梯形

1027 牛牛学矩形

1028 牛牛学立体

1029 计算三角形的周长和面积

1030 你能活多少秒

1031 时间转换

1032 温度转换

1033 计算机内存

1034 [NOIP2017]成绩

1035 KiKi的最高分

1036 组队比赛

1037 平方根

1038 长方体

1039 使徒袭来

1040 白兔的分身术

1041 纸牌

1042 Tobaku Mokushiroku Kaiji

1043 珂朵莉的假动态仙人掌

1044 旅游观光

1045 [NOIP2002]自由落体

1046 挂科

1047 得不到的爱情


1001 这是一道签到题

str = ['zhe','shi','yi','dao','qian','dao','ti']
print('\n'.join(str))

1002 排列式

# 解法一:
final_anslis = []
for first in range(1,100):
    for second in range(100,9999):
        ans = first*second
        if ans>9999:
            continue;
        lista = []
        if first<10:
            lista+=str(first)
        else:
            lista+=str(first%10)
            lista+=str(first//10)
        if second<1000:
            lista+=str(second%10)
            lista+=str(second//10%10)
            lista+=str(second//100)
        else:
            lista+=str(second%10)
            lista += str(second // 10 % 10)
            lista += str(second // 100 % 10)
            lista += str(second//1000)
        lista += str(ans % 10)
        lista += str(ans // 10 % 10)
        lista += str(ans // 100 % 10)
        lista += str(ans // 1000)
        lista = list(set(lista))
        if len(lista)==9 and ('0' not in lista):
            s = '%d = %d x %d' % (ans,first,second)
            final_anslis.append(s)
final_anslis.sort()
for i in final_anslis:
    print(i)


# 解法二:暴力循环
# 第一种: z = a.b.c.d      x1 = e      y1 = f.g.h.i
# 第二种: z = z.b.c.d      x2 = e.f    y2 = g.h.i
for a in range(1,10):
    for b in range(1,10):
        if a != b:
            for c in range(1,10):
                if a != c and b != c:
                    for d in range(1,10):
                        if a != d and b != d and c != d:
                            for e in range(1,10):
                                if a != e and b != e and c != e and d != e:
                                    for f in range(1,10):
                                        if a != f and b != f and c != f and d != f and e != f:
                                            for g in range(1,10):
                                                if a != g and b != g and c != g and d != g and e != g and f != g:
                                                    for h in range(1,10):
                                                        if a != h and b != h and c != h and d != h and e != h and f != h and g != h:
                                                            for i in range(1,10):
                                                                if a != i and b != i and c != i and d != i and e != i and f != i and g != i and h != i:
                                                                    x1 = e
                                                                    y1 = f * 1000 + g * 100 + h * 10 + i
                                                                    x2 = e * 10 + f
                                                                    y2 = g * 100 + h * 10 + i
                                                                    z  = a * 1000 + b * 100 + c * 10 + d
                                                                    if x1 * y1 == z and x1 < 10:
                                                                        print('{} = {} x {}'.format(z, x1, y1))
                                                                    if x2 * y2 == z:
                                                                        print('{} = {} x {}'.format(z,x2,y2))

1003 小飞机

str = '**'
str1 = '  '.join(str)
str_1 = str.center(12,' ')
str_2 = str * 6
str_3 = str1.center(12,' ')
print(str_1)
print(str_1)
print(str_2)
print(str_2)
print(str_3)
print(str_3)

1004 学姐的"Helloworld"

print("Helo word!")

1005 乘法表

for i in range(1,10):
    for j in range(1,i+1):
        sum = i * j
        print('{}*{}={}'.format(j,i,repr(sum).rjust(2)),end=' ')
    print('  ')

1006 KiKi学程序设计基础

a = r'''printf("Hello world!\n");'''
b = r'''cout << "Hello world!" << endl;'''
print(a)
print(b)

1007 疫情死亡率

a,b = map(int, input().split())
c = b / a
print('{:.3%}'.format(c))

1008 爱因斯坦的名言

print(r'''"Genius is 1% inspiration and 99% perspiration."''')

1009 字符串输出1.0

str = 'Welcome to ACM / ICPC!'
for i in range(3):
    print(str)

1010 牛牛学说话之-整数

n = int(input())
print(n)

1011 牛牛学说话之-浮点数

a = float(input())
print("%.3f"%a)

1012 牛牛学加法

a,b = map(int,input().split())
print(a+b)

1013 牛牛学除法

a,b = map(int,input().split())
print(int(a/b))

1014 牛牛学取余

a,b = map(int,input().split())
print(a%b)

1015 浮点除法

a,b = map(int,input().split())
print('%.3f'%(a/b))

1016 计算带余除法

a,b = map(int,input().split())
print("{} {}".format(int(a/b),a%b))

1017 水题再次来袭:明天是星期几?

a = int(input())
if a == 7:
    print('1')
else:
    print(a+1)

1018 开学?

X,N = map(int,input().split())
sum = (X + N) % 7
if sum == 0:
    print('7')
else:
    print(sum)

1019 helloworld

str = 'hello world'
for i in str:
    print(chr(ord(i)+1),end='')

1020 a+b

a,b = map(int,input().split())
print('%x'%(a+b))

1021 整数的个位

a = int(input())
print(a%10)

1022 整数的十位

a = int(input())
print(a//10%10)

1023 反向输出一个四位数

str = input()
print(str[::-1])

1024 总成绩和平均分计算

a,b,c = map(float,input().split())
sum = a + b + c
ave = (a+b+c)/3
print('{:.2f} {:.2f}'.format(sum,ave))

1025 计算平均成绩

a,b,c = map(float,input().split())
sum = a + b + c
ave = (a+b+c)/3
print('{:.2f} {:.2f}'.format(sum,ave))

1026 牛牛学梯形

up,down,height = map(float,input().split())
area = (up + down) * height / 2
print('%.3f'%area)

1027 牛牛学矩形

a,b = map(float,input().split())
len = (a +  b) * 2
area = a * b
print(int(len))
print(int(area))

1028 牛牛学立体

a,b,c = map(int,input().split())
print((a*b+b*c+c*a) * 2)
print(a*b*c)

1029 计算三角形的周长和面积

up,down,height = map(float,input().split())
p = (up + down + height) / 2
area = (p*(p-up)*(p-down)*(p-height)) ** 0.5
circumference = p * 2
print('circumference={:.2f} area={:.2f}'.format(circumference,area))

1030 你能活多少秒

a = int(input())
s = 3.156 * pow(10,7)
print(int (a * s))

1031 时间转换

seconds = int(input())
h = int(seconds / 3600)
m = int((seconds % 3600 - seconds % 60) / 60)
s = int(seconds % 60)
print(h,m,s)

1032 温度转换

f = float(input())
c = 5/9 * (f -32)
print('%.3f'%c)

1033 计算机内存

n = int(input())
print(int(n * 1024 * 1024 / 4))

1034 [NOIP2017]成绩

a,b,c = map(int,input().split())
print(int(a * 0.2 + b * 0.3 + c * 0.5))

1035 KiKi的最高分

a,b,c = map(int,input().split())
print(int(max(a,b,c)))

1036 组队比赛

a,b,c,d = map(int,input().split())
s = [a,b,c,d]
s.sort()
x = (s[0] + s[3]) - (s[1] + s[2])
if x < 0 :
    x = -x
print(x)

1037 平方根

x = (int(input())) ** 0.5
print(int(x))

1038 长方体

x1,x2,x3 = map(int,input().split())
a = int((x1 * x2 / x3) ** 0.5)
b = int((x1 * x3 / x2) ** 0.5)
c = int((x2 * x3 / x1) ** 0.5)
s = int(a + b + c) * 4
print(s)

1039 使徒袭来

x = int(input())
print('{:.3f}'.format((x ** (1/3)) * 3))

1040 白兔的分身术

n = int(input())
print(n+1)

1041 纸牌

n = int(input())
if n % 2 == 0:
    print(int(n/2))
else:
    print((n//2+1))

1042 Tobaku Mokushiroku Kaiji

a,b,c,d,e,f = map(int,input().split())
x1 = min(a,e)
x2 = min(b,f)
x3 = min(c,d)
print(x1 + x2 + x3)

1043 珂朵莉的假动态仙人掌

n = int(input())
if n % 3 == 0:
    t = (n // 3) * 2
    print(int(t))
else:
    t = (n // 3) * 2 + 1
    print(int(t))

1044 旅游观光

n = int(input())
if n%2 == 0:
    print(int(n/2-1))
else:
    print(int(n//2))

1045 [NOIP2002]自由落体

H,S1,V,L,K,n = map(float,input().split())
n = int(n)
t1 = ((H-K)/5) ** 0.5
t2 = (H/5)  ** 0.5
x1 = S1 - V*t1 + L + 0.00001
x2 = S1 - V*t2 - 0.00001
a = 0    # a的值就是可被接受到的n的一个范围
for i in range(0,n,1):
    if x1 > i and x2 < i:
        a = a + 1
print(a)

1046 挂科

n,x,y = map(int,input().split())
max = min(x,y)
if x+y <= n :
    min = 0
else:
    min = x+y-n
print('{} {}'.format(max,min))

1047 得不到的爱情

N,M = map(int,input().split())
print(N*M-N-M)

# 本题参考链接:
# 1. https://blog.csdn.net/weixin_63045509/article/details/122899297
# 2. https://www.luogu.com.cn/blog/jszjinshengzhi/luogu-p3951-xiao-kai-di-ni-huo-2017-tg-day1-t1-post

本篇内容如有错误或对解题过程存有疑问、更改建议和提升空间等,欢迎私信讨论,一起变得更强!

你可能感兴趣的:(python,python)