赛码网练习 翻转数组

总结下需要注意的地方。
1.python2.7 需要用raw_input()读输入
2.把一组输入的字符串类型的数字转换成数组需要注意:

L = [int(i) for i in L.split()]

用split()去掉空格,然后用int()保证数组里面是整数类型(字符串类型排序会出现问题)

AC代码:

L = raw_input()
L = [int(i) for i in L.split()]

def check(L):
    Lsort = L[:]
    Lsort.sort()

    C = []
    for i in range(len(L)):
        if L[i] != Lsort[i]:
            C.append(i)

    if sorted(L[C[0]:C[-1]+1]) == L[C[0]:C[-1]+1][::-1]:
        return 'yes'


    else:
        return 'no'

    
print(check(L))

你可能感兴趣的:(赛码网练习 翻转数组)