1.合并表记录
dict={}
a=int(input())
for i in range(a):
key,value=map(int,input().split()) #map() 会根据提供的函数对指定序列做映射,map(function, iterable, ...)
#输出的是字符串,要想读取的是数值
if key in dict.keys():
dict[key]=dict[key]+value
else:
dict[key]=value
dic=sorted(dict.keys())
for i in dict:
print(i,dict[i])
- 字串的连接最长路径查找
while True:
try:
num = int(input())
l = []
for i in range(num):
l.append(input())
res = sorted(l)
for i in res:
print(i)
except:
break
3.坐标移动
import sys
while True:
try:
inval = sys.stdin.readline().split(';')
initx = 0
inity = 0
for i in inval:
if i[0] == 'A':
initx -= int(i[1:])
if i[0] == 'D':
initx += int(i[1:])
if i[0] == 'W':
inity += int(i[1:])
if i[0] == 'S':
inity -= int(i[1:])
else:
continue
print (str(initx) + ',' + str(inity))
except:
break
4.实现删除字符串中出现次数最少的字符,若多个字符出现次数一样,则都删除。输出删除这些单词后的字符串,字符串中其它字符保持原来的顺序。
while True:
try:
s = input()
result = []
num = []
for i in s:
num.append(s.count(i))
min_num = min(num)
for i,j in zip(s,num):
if j != min_num:
result.append(i)
print(''.join(result))
except:
break
网友评论