去哪儿0AC代码-为啥复制过来这么多乱码
# 一个正整数的数组 arr,数组满足0 <= arr[i] <= 9,挑出任意个数组成一个最大的数, # 并且能被3整除,并以字符串形式返回。50% #!/bin/python # -*- coding: utf8 -*- import sys import os import re class Solution: def solution(self, d): n = len(d) ans = [] d.sort(reverse=True) for i in d: if i % 3 == 0: ans.append(str(i)) t1 = 8 in d and (7 in d or 4 in d or 1 in d) t2 = 7 in d and (5 in d or 2 in d) t3 = 5 in d and (4 in d or 1 in d) t4 = 4 in d and 2 in d t5 = 2 in d and 1 in d while t1 or t2 or t3 or t4 or t5: if 8 in d: if 7 in d: ans.append(str(8)) ans.append(str(7)) d.remove(8) d.remove(7) elif 4 in d: ans.append(str(8)) ans.append(str(4)) d.remove(8) d.remove(4) elif 1 in d: ans.append(str(8)) ans.append(str(1)) d.remove(8) d.remove(1) if 7 in d: if 5 in d: ans.append(str(7)) ans.append(str(5)) d.remove(7) d.remove(5) elif 2 in d: ans.append(str(7)) ans.append(str(2)) d.remove(7) d.remove(2) if 5 in d: if 4 in d: ans.append(str(5)) ans.append(str(4)) d.remove(5) d.remove(4) elif 1 in d: ans.append(str(5)) ans.append(str(1)) d.remove(5) d.remove(1) if 4 in d: if 2 in d: ans.append(str(4)) ans.append(str(2)) d.remove(4) d.remove(2) if 2 in d: ans.append(str(2)) ans.append(str(1)) d.remove(2) d.remove(1) t1 = 8 in d and (7 in d or 4 in d or 1 in d) t2 = 7 in d and (5 in d or 2 in d) t3 = 5 in d and (4 in d or 1 in d) t4 = 4 in d and 2 in d t5 = 2 in d and 1 in d ans.sort(reverse=True) if len(ans) == 0: return '' else: return ''.join(ans[i] for i in range(len(ans))) _d_cnt = 0 _d_cnt = int(input()) _d_i = 0 _d = [] while _d_i < _d_cnt: _d_item = int(input()) _d.append(_d_item) _d_i += 1 s = Solution() res = s.solution(_d) print(res + "\n") # 给定一个整数数组m,逐次选出任意整数,请返回所有对应整数、对应选出的次数的乘积之和能达到的最大值, # 可以放弃选择某些元素。比如数组元素为[a1,a2,a3,a4],依次选择a3,a2和a4,乘积之后的结果就是a3*1+a2*2+a4*3。 # 89% import sys import os import re class Solution: def solution(self, arr): arr.sort() n = len(arr) ans = 0 ans1 = 0 ans2 = 0 ans3 = 0 ans4 = 0 for i in range(n-1): if arr[i] <= 0 and arr[i+1] > 0: t1 = 1 t2 = 1 t3 = 1 t4 = 1 t5 = 1 for j in range(i, n): ans += t1 * arr[j] t1 += 1 for k in range(i-1, n): if k >= 0: ans1 += t2 * arr[k] t2 += 1 for w in range(i-2, n): if w >= 0: ans2 += t3 * arr[w] t3 += 1 for w1 in range(i-3, n): if w1 >= 0: ans3 += t4 * arr[w1] t4 += 1 return max(ans, ans1, ans2, ans3, ans4) _arr_cnt = 0 _arr_cnt = int(input()) _arr_i = 0 _arr = [] while _arr_i < _arr_cnt: _arr_item = int(input()) _arr.append(_arr_item) _arr_i += 1 s = Solution() res = s.solution(_arr) print(str(res) + "\n") # Lisa 喜欢字符串,尤其是长字符串。对于每个字符串,她都有专门的评价体系来判断字符串的优雅程度。 # 她定义一个字符串 S[1..3n−2] (n≥2) 是一个半回文当且仅当它满足 S[i]=S[2n−i]=S[2n+i−2] (1≤i≤n) . # 例如dfgfdfg是一个半回文串,而dfgjfdfgj不是。现在,Lisa 生成了一些长字符串。 # 她请求你帮助找出有多少个半回文子串。优雅的字符串 60% #!/bin/python # -*- coding: utf8 -*- import sys import os import re class Solution: def solution(self, n, str): m = len(str) if m % 2 == 0: ans = 3 else: ans = 2 return ans n = int(input()) try: str = input() except: str = None s = Solution() res = s.solution(n, str) print(res)
#去哪儿##笔经#