看到网上有小米的运维笔试题,我用python试着做了一下,结果应该是满足了题目要求,因为没有官方测试。
编程题一:
#!/usr/bin/env python
#coding:utf-8
"""
file:.py
date:2018/9/20 19:56
author: peak
description:
"""
def test():
times = raw_input("times:")
N = raw_input("N:")
K = raw_input("K:")
ks = []
alltimes=0
times = times.replace('[', '')
times = times.replace(']', '')
times = times.replace(',', '')
list=[]
i = 0
while i<len(times):
lis = times[i:i+3]
li=[]
for r in lis:
li.append(int(r))
list.append(li)
i+=3
for j in list:
if j[0] == int(K):
ks.append(j)
if len(ks) < int(N)-1 :
print '-1'
else:
for m in ks:
alltimes = m[1]+m[2]
return alltimes
print test()
编程题2:
#!/usr/bin/env python
#coding:utf-8
"""
file:.py
date:2018/9/20 22:17
author: peak
description:
"""
def turnlist(x):
if ',' in x:
x = x.split(',')
return x
else:
x = x.split()
return x
def exam2():
L1 = raw_input("N,T:")
Str = raw_input("string:")
L1 = turnlist(L1)
N = L1[0]
T = int(L1[1])
for i in range(T):
L2 = raw_input("type,X:")
L2 = turnlist(L2)
X = L2[1]
X = int(X)
if L2[0] == "1":
head = Str[0:-X]
s1 = Str.replace(head, "")
S = s1+head
print S
else:
print Str[X]
exam2()