1. 数列描述
示例代码:
a0 = '1'
N = 4
def fun(a0):
result = ''
left = 0
cursor = 0
while cursor < len(a0):
if a0[cursor] != a0[left]:
count = cursor -left
result += "{}{}".format(str(count),a0[left])
left = cursor
cursor += 1
count = cursor - left
result += "{}{}".format(str(count),a0[left])
return result
def fun1(a0,N):
i = 1
res = None
while i <= N:
res = fun(a0)
a0 = res
i += 1
return res
r = fun1(a0,4)
print(r)
2. 矩阵最大值
题目描述:
示例代码:
N = 5
s = [
'1,0,0,0,1',
'0,0,0,1,1',
'0,1,0,1,0',
'1,0,0,1,1',
'1,0,1,0,1'
]
def fun1(s1,s2):
r1 = int(s1,2)
r2 = int(s2,2)
return r1 if r1 > r2 else r2
def fun(s,N):
n = 1
result = []
while n <= N:
if n % 2 == 1:
s_list = s[n - 1].split(',')
left1 = ''.join(s_list[1:]) + s_list[0]
right1 = s_list[-1] + ''.join(s_list[:-1])
result.append(fun1(left1,right1))
else:
s_list = s[n - 1].split(',')
left2 = ''.join(s_list[2:] + s_list[0:2])
right2 = ''.join(s_list[-1:-3:-1] + s_list[:-2])
result.append(fun1(left2,right2))
n += 1
return sum(result)
r = fun(s,N)
print(r)
3. 数据分类
示例代码:
s1 = 3
ss1 = 4
sss1 = [256, 257, 258, 259, 260, 261, 262, 263, 264, 265]
tmp_dict = {'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15}
def fun(num):
num_str = hex(num)[2:]
tmp = [tmp_dict[_] if _ in tmp_dict else int(_) for _ in num_str]
return sum(tmp)
def fun1(s,ss,sss):
tmp_list = [fun(_) for _ in sss]
tmp1_list = [_ % ss for _ in tmp_list]
res = []
for i in range(s):
res.append(tmp1_list.count(i))
return max(res)
r = fun1(s,ss,sss)
print(r)