历年题解 CCF CSP历年题解(python)
样例输入:
albw:x 4 ls -a -l -a documents -b ls ls -w 10 -x -w 15 ls -a -b -c -d -e -l
题目链接: 201403-3命令行选项
问题分析:
建两个列表分别存带参和不带参选项,合法选项排序输出,不合法停止分析下一条命令
满分例程: 来源:CCF 201403-3 命令行选项(Python100分)
“{}.format()” 输出格式化方法
string = input()
n = int(input())
a = []
b = []
i = len(string) - 1
while i >= 0:
if string[i] == ':':
b.append(string[i - 1])
i -= 1
else:
a.append(string[i])
i -= 1
for i in range(n):
d = {}
c = list(input().split(' '))
print('Case {}: '.format(i + 1), end='')
if len(c) > 1:
j = 1
while j < len(c):
if c[j][0] == '-' and c[j][1] in a:
d[c[j]] = ''
elif c[j][0] == '-' and c[j][1] in b and j + 1 < len(c):
d[c[j]] = c[j + 1]
j += 1
else:
break
j += 1
d = sorted(d.items(), key=lambda x: x[0])
print(type(d))
for x, y in d:
print(x, y, end=' ')
print()
|