SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top