滴滴笔试 算式转移

心态崩了,第一题想了好久,只a了36,大佬们知道边界条件吗?我感觉我写的没啥问题,虽然存在超参数,但是调高了也没用啊。

n = int(input())
strr =input()
str_list =strr.split()
ooo = eval(strr)
#print(strr)
def list2str(aa):
    bb=''
    for i in aa:
        bb+=i
        bb+=' '
    return bb
for j in range(50):
    for i in range(len(str_list)-2):
        if str_list[i] not in ['+', '-', '*', '/']:
            if int(str_list[i]) > int(str_list[i + 2]):
                list_temp = str_list.copy()
                temp = list_temp[i]
                list_temp[i] = list_temp[i + 2]
                list_temp[i + 2] = temp
                if eval(list2str(list_temp)) == ooo:
                    str_list = list_temp
print(list2str(str_list))
#滴滴##笔试题目##秋招#
全部评论
第一题可看AC代码:https://www.nowcoder.com/discuss/235697
点赞 回复 分享
发布于 2019-08-27 21:34
边界我感觉是*前面的运算如果是/那么被除数是不能交换的,如果不是/,是可以交换的
点赞 回复 分享
发布于 2019-08-31 13:49
这个你是把每个符号左右两边的数都进行大小比较了吗? + * 等级不一样,3 + 2 + 1 + -4 * -5 + 1 这里的 -4 和 1 不能换啊
点赞 回复 分享
发布于 2019-08-27 21:31

相关推荐

头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务