NOC大赛 Python编程复赛模拟题: 挑战你的代码能力
NOC大赛 Python编程复赛模拟题: 挑战你的代码能力
背景介绍
“全国中小学信息技术创新与实践大赛”是一项运用信息技术,培养广大师生的创新精神和实践能力,面向青少年学生开展人工智能科学普及、引领科技创新的素质教育实践平台,简称NOC大赛(NOC为Novelty, Originality, Creativity的缩写)。
模拟题目
以下提供八道模拟题,供你练习:
1. 最长最短单词
输入一行句子,输出第一个最长的单词和第一个最短的单词。
输入格式: 一行句子
输出格式: 两行输出,第一行为第一个最长的单词,第二行为第一个最短的单词。
输入样例: I am studying Programming language C in Peking University
输出样例: Programming I
Python3代码如下:
string = input()
words = string.split()
longest_word = words[0]
shortest_word = words[0]
for word in words:
if len(word) > len(longest_word):
longest_word = word
if len(word) < len(shortest_word):
shortest_word = word
print(longest_word)
print(shortest_word)
2. 判断光的颜色
输入一个整数,表示光的波长(单位:nm),判断光的颜色,不可见则输出'invisible light'。
输入格式: 一个整数,表示光的波长(单位:nm)
输出格式: 输出光的颜色,不可见则输出'invisible light'。
输入样例: 750
输出样例: red
Python3代码如下:
wavelength = int(input())
if 770 <= wavelength <= 622:
color = 'red'
elif 621 <= wavelength <= 597:
color = 'orange'
elif 596 <= wavelength <= 577:
color = 'yellow'
elif 576 <= wavelength <= 492:
color = 'green'
elif 491 <= wavelength <= 455:
color = 'blue'
elif 454 <= wavelength <= 350:
color = 'purple'
else:
color = 'invisible light'
print(color)
3. 数的性质
输入一个数字,判断是否符合以下性质,并输出这4个人是否喜欢这个数字。
- 小A 喜欢同时满足两个性质的数字;
- Uim 喜欢至少符合其中一种性质的数字;
- 八尾勇喜欢刚好有符合其中一个性质的数字;
- 正妹喜欢不符合这两个性质的数字。
输入格式: 输入一个数字x(0≤x≤1000)
输出格式: 输出这 4 个人是否喜欢这个数字,如果喜欢则输出1,否则输出0,用空格分隔。
输入样例: 12
输出样例: 1 1 0 0
Python3代码如下:
x = int(input())
# 性质1:是偶数
property1 = x % 2 == 0
# 性质2:大于 4 且不大于 12
property2 = 4 < x <= 12
# 判断每个人的喜好
XiaoA = int(property1 and property2)
Uim = int(property1 or property2)
BaoweiYong = int((property1 and not property2) or (not property1 and property2))
Zhengmei = int(not property1 and not property2)
print(XiaoA, Uim, BaoweiYong, Zhengmei)
4. 判断能否被3,5,7整除
给定一个整数,判断它能否被3,5,7整除,并输出以下信息:
- 能同时被3,5,7整除(直接输出3 5 7,每个数中间一个空格);
- 只能被其中两个数整除(输出两个数,小的在前,大的在后。例如:3 5或者 3 7或者5 7,中间用空格分隔);
- 只能被其中一个数整除(输出这个除数);
- 不能被任何数整除,输出'no'。
输入格式: 输入一行,包括一个整数。
输出格式: 输出一行,按照描述要求给出整数被3,5,7整除的情况。
输入样例: 105
输出样例: 3 5 7
Python3代码如下:
n = int(input())
if n % 3 == 0 and n % 5 == 0 and n % 7 == 0:
print('3 5 7')
elif n % 3 == 0 and n % 5 == 0:
print('3 5')
elif n % 3 == 0 and n % 7 == 0:
print('3 7')
elif n % 5 == 0 and n % 7 == 0:
print('5 7')
elif n % 3 == 0:
print(3)
elif n % 5 == 0:
print(5)
elif n % 7 == 0:
print(7)
else:
print('no')
5. 计算总分
输入多行数据,每行数据包含一个学生姓名和三门课成绩,计算每个学生的总分,并按照总分降序输出学生姓名和总分。
输入格式: 第一行输入学生人数n,后面n行,每行输入一个学生姓名和三门课成绩,用空格分隔。
输出格式: 按照总分降序输出学生姓名和总分,每个学生信息占一行,用空格分隔。
输入样例: 3 张三 80 90 70 李四 90 80 85 王五 75 85 90
输出样例: 李四 255 王五 250 张三 240
Python3代码如下:
n = int(input())
students = []
for i in range(n):
name, score1, score2, score3 = input().split()
students.append((name, int(score1) + int(score2) + int(score3)))
students.sort(key=lambda x: x[1], reverse=True)
for name, total_score in students:
print(name, total_score)
6. 判断字符串是否回文
输入一个字符串,判断它是否是回文串。
输入格式: 输入一行,包括一个字符串。
输出格式: 输出一行,如果字符串是回文串,输出'yes',否则输出'no'。
输入样例: level
输出样例: yes
Python3代码如下:
string = input()
if string == string[::-1]:
print('yes')
else:
print('no')
7. 统计数字出现次数
输入一行字符串,统计其中每个数字出现的次数,并按照数字从小到大输出。
输入格式: 输入一行,包括一个字符串。
输出格式: 输出多行,每行输出一个数字及其出现的次数,用空格分隔,数字从小到大输出。
输入样例: 12345678901234567890
输出样例: 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2
Python3代码如下:
string = input()
count = {}
for char in string:
if char.isdigit():
if char in count:
count[char] += 1
else:
count[char] = 1
for num in sorted(count.keys()):
print(num, count[num])
8. 查找最小的数
输入一行数字,用空格分隔,查找其中的最小数。
输入格式: 输入一行,包括多个数字,用空格分隔。
输出格式: 输出一行,包括最小数。
输入样例: 10 5 20 15 3
输出样例: 3
Python3代码如下:
nums = [int(x) for x in input().split()]
min_num = nums[0]
for num in nums:
if num < min_num:
min_num = num
print(min_num)
结语
希望这些模拟题能够帮助你更好地备战NOC大赛,祝你取得好成绩!
原文地址: https://www.cveoy.top/t/topic/ob3P 著作权归作者所有。请勿转载和采集!