Define a function SWAP(SCORES) to swap all those values in the list of SCORES, which are alternate elements. For example: If the SCORES contain [200, 456, 300, 100, 234, 678], the output should be displayed as [300, 200, 100, 456, 678, 234].
现在的安排模式是特殊的,因为如果[1,2,3,4,5,6]是命令,那么结果就是命令[3,1,4,2,6,5]。
while True:
l=eval(input( List: ))
x=len(l)
n=x//4
t=4*n
l1=l[:t]
print(l1)
l2=l[t:]
print(l2)
for i in range((len(l1)//2)):
l1[i],l1[i+2]=l1[i+2],l1[i]
#l1 shuffling over
if len(l2)==1:
l1+=l2
print( Shuffled list: ,l1)
elif len(l2)>=2:
l2=l2[::-1]
l1+=l2
print( Shuffled list: ,l1)
elif len(l2)==0:
print( Shuffled list: ,l1)
#treating l2 separately
这是我所尝试的,对我来说,这确实是行之有效的。
================================== RESTART: C:/Users/Harikrishnan/OneDrive/Desktop/peculiar shuffling q.py ==================================
List: [200,456,300,100,234,678]
[200, 456, 300, 100]
[234, 678]
Shuffled list: [300, 100, 200, 456, 678, 234]
List: [1,2,3,4]
[1, 2, 3, 4]
[]
Shuffled list: [3, 4, 1, 2]
List: [1,2,3,4,5]
[1, 2, 3, 4]
[5]
Shuffled list: [3, 4, 1, 2, 5]
List: [1,2,3,4,5,6,7]
[1, 2, 3, 4]
[5, 6, 7]
Shuffled list: [3, 4, 1, 2, 7, 6, 5]
List: [1,2,3,4,5,6,7,8]
[1, 2, 3, 4, 5, 6, 7, 8]
[]
Shuffled list: [3, 4, 5, 6, 1, 2, 7, 8]
List:
Traceback (most recent call last):
File "C:/Users/Harikrishnan/OneDrive/Desktop/peculiar shuffling q.py", line 2, in <module>
l=eval(input( List: ))
KeyboardInterrupt
我的逻辑是:直到第4点,所有东西都是罚款的。 Od的立场论点是 s弄的,甚至立场论点是 s弄的,在四起案件发生后:
- Nothing was left after the 4n elements.
- 1 element was left,
- 2 elements were left,
- 3 elements were left.
我的朋友有另一个逻辑:
i 认为这一模式是最后两个因素,最后三个是第5号,最后四个是第6号,最后七个是第10号,最后八个是第11号是第12号
现在我感到困惑。 我们谁是正确的?