Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1.  
  2. def summ(x):
  3. s=0
  4. w=x
  5. while w>0:
  6. s+=w%10
  7. w//=10
  8. return s
  9.  
  10.  
  11. Fin=open("input.txt")
  12. Fout=open("output.txt", "w")
  13.  
  14. A=[]
  15.  
  16. while True:
  17. s=Fin.readline()
  18. if not s: break
  19. A.append(int(s))
  20. N=len(A)
  21. for i in range(N-1):
  22. for j in range(N-i-1):
  23. if summ(A[j]) > summ(A[j+1]):
  24. A[j], A[j+1] = A[j+1], A[j]
  25.  
  26. print(A)
  27. Fout.write(str(A))
  28. Fin.close()
  29. Fout.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement