第一题
moves = input()
x, y = 0, 0
for move in moves:
if move == "L":
x -= 1
elif move == "R":
x += 1
elif move == "U":
y += 1
elif move == "D":
y -= 1
if x == 0 and y == 0:
print('true')
else:
print('false')
第二题
target = input()
nums = [2, 7, 11, 15]
lens = len(nums)
jieguo = False
for i in range(lens):
for j in range(i+1, lens):
if nums[j] + nums[i] == int(target):
x = [i, j]
jieguo = True
print(x)
break
if jieguo:
break
第三题
def huiwen(s: str) -> int:
a = 0
x = []
for i in s:
n = s.count(i)
if n >= 2 and not i in x:
a += n - n % 2
x.append(i)
if a == len(s):
return a
elif len(s) ==2:
return 2
else:
return a + 1
第四题
nums = [4, 1, 2, 0]
x = len(nums) + 1
for i in range(x):
n = 0
for j in nums:
if i == j:
n = 1
break
if n == 0:
print(i)
break
第五题
def shuzihe(num: int = 30) -> int:
ten = (num - num % 10) // 10
shengxia = num % 10
init = 4
n = 0
if ten > 0:
n += init
n += 5 * (ten-1)
for i in range(1, shengxia + 1):
if (i + ten) % 2 == 0:
n += 1
return n
print(shuzihe(10))
第六题
timePoints = ["01:00","02:00","04:00"]
min_m = 9999
for i in range(len(timePoints) - 1):
one = timePoints[i].split(':')
two = timePoints[i + 1].split(':')
time_1, time_2 = int(one[0]), int(two[0])
minute_1, minute_2 = int(one[1]), int(two[1])
if time_1 == 0:
time_1 = 24
if time_2 == 0:
time_2 = 24
time_1, time_2 = time_1*60, time_2*60
o = time_1 + minute_1
t = time_2 + minute_2
x = t - o
if x <min_m:
if x < 0:
x *= -1
min_m = x
print(min_m)
第七题
nums1, nums2 = [4,9,5], [9,4,9,8,4]
x = []
for i in nums1:
for j in nums2:
if j in x :
break
if i == j:
x.append(j)
print(x)
第八题
nums = [-1,0,3,5,9,12]
target = 9
x = False
for i in range(len(nums)):
if target == nums[i]:
print(i)
x = True
break
if not x:
print(-1)
第九题
circles = [[2,2,2],[2,2,5]]
n = 0
gezi = []
for o in circles:
min_x = o[0] - o[2]
max_x = o[0] + o[2]
min_y = o[1] - o[2]
max_y = o[1] + o[2]
n_r = 2*o[2] + 1
for x in range(min_x, max_x + 1):
for y in range(min_y, max_y + 1):
total_x = (x - o[0])
total_y = (y - o[1])
if total_x < 0:
total_x *= -1
if total_y < 0:
total_y *= -1
long = pow(total_x ** 2 + total_y ** 2, 0.5)
if long <= o[2]:
if not [x,y] in gezi:
gezi.append([x,y])
n += 1
print(n)