1:题目
将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。
x=input("")
x=x[::-1] #列表切片,逆序输出
print(x)
2:题目
字符串的输入输出处理。
n=int(input())
for i in range(n):
x=input()
print(x)
print()
while True:
x=input().split()
for i in x:
print(i)
print()
3:题目Minesweeper Have you ever played Minesweeper? This cute little game comes with a certain operating system whose name we can't remember. The goal of the game is to find where all the mines are located within a M x N field. The game shows a number in a square which tells you how many mines there are adjacent to that square. Each square has at most eight adjacent squares. The 4 x 4 field on the left contains two mines, each represented by a ``*'' character. If we represent the same field by the hint numbers described above, we end up with the field on the right: *... .... .*.. .... *100 2210 1*10 1110
翻译:你玩过扫雷吗?这个可爱的小游戏附带了一个我们记不得名字的操作系统。游戏的目标是找出所有的地雷都在一个M×N的区域内。游戏在一个正方形中显示一个数字,它告诉你在这个正方形附近有多少地雷。每个方块最多有八个相邻方块。“4”在左边的字段中包含两个由“4”表示的地雷。如果我们用上面描述的提示数字来表示同一个字段,那么右边的字段就是:。*.. .... *100 2210 1*10 1110
count = 1
while True:
a, b = map(int, input().strip().split())
# a和b都是0则退出
if a == 0 and b == 0:
break
else:
# 输入,把数据都存放在列表里,形成一个二维列表
ls = []
for i in range(a):
ls1 = []
n = input()
for j in n:
ls1.append(j)
ls.append(ls1)
# 对数据进行操作,先将所有的"."换成数字0,在判断周围有多少个雷,有就加1,判断周围的雷分别有4,5,8次
for i in range(a):
for j in range(b):
if ls[i][j] == '.':
ls[i][j] = 0
for i in range(a):
for j in range(b):
if ls[i][j] == '*':
# 判断左上角是否有雷
if i - 1 >= 0 and j - 1 >= 0 and ls[i-1][j-1] != "*":
ls[i-1][j-1] += 1
# 判断左边是否有雷
if j - 1 >= 0 and ls[i][j-1] != "*":
ls[i][j-1] += 1
# 判断左下角是否有雷
if i + 1 <= a - 1 and j - 1 >= 0 and ls[i+1][j-1] != '*':
ls[i+1][j-1] += 1
# 判断上面是否有雷
if i - 1 >= 0 and ls[i-1][j] != '*':
ls[i-1][j] += 1
# 判断下面是否有雷
if i + 1 <= a-1 and ls[i+1][j] != '*':
ls[i+1][j] += 1
# 判断右上角是否有雷
if i - 1 >= 0 and j + 1 <= b - 1 and ls[i-1][j+1] != '*':
ls[i-1][j+1] += 1
# 判断右边是否有雷
if j + 1 <= b - 1 and ls[i][j+1] != '*':
ls[i][j+1] += 1
# 判断右下角是否有雷
if i + 1 <= a - 1 and j + 1 <= b - 1 and ls[i+1][j+1] != "*":
ls[i+1][j+1] += 1
# 输出数据,并且统计执行次数
print("Field #{}:".format(count))
for i in ls:
for j in i:
print(j, end='')
print()
print()
count += 1