0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

リスト

Last updated at Posted at 2018-09-01

トランプ4枚(9まで)a,b,c,dを並び替え二つの数字を作り、足し算し最大の和を求める
例)2,9,8,3→93+82=175

numbers=input() #値の取得
n_list=list(numbers) #リストに格納 
while ' ' in n_list:
    n_list.remove(' ') #空白が邪魔なのでremoveで取り除く

n_list_i=[int(s) for s in n_list] #数値に変換
n_list_i2=sorted(n_list_i,reverse=True) #降順に並び替え

n1=n_list_i2[0]*10 
n2=n_list_i2[1]*10 #10の位なので
n3=n_list_i2[2]
n4=n_list_i2[3]

ns=(n1+n3)+(n2+n4)
print(ns)

もっと簡潔に書きたいなあ
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?