SHARE
TWEET

Untitled

a guest Aug 19th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = int(input())
  2. tab = []                            #contient les depassements
  3. l = input().split(" ")
  4. for i in range(len(l)):
  5.     l[i] = int(l[i])
  6. t = []                              #contient les chiffres de 1 a n dans l'ordre croissant
  7. s = 0                               #somme des croisements
  8. k = 1
  9. for i in range(1,n+1):
  10.     t.append(k)
  11.     k = k + 1
  12.  
  13. for i in range(1, n+1):
  14.     if t[i-1] != l[i-1]:
  15.         a = l.index(t[i-1])
  16.         while a > i-1:
  17.             f = "{} {}".format(l[a-1], l[a])  
  18.             tab.append(f)
  19.             l[a-1], l[a] = l[a], l[a-1]         #changement de positions
  20.             s = s + 1
  21.             a = l.index(t[i-1])
  22. print(s)
  23. for i in range(len(tab)):
  24.     print(tab[i])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top