0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CpawCTF Q14.[PPC]並べ替えろ! をpythonで解いた

Posted at

とりあえずpythonでコードを書いてやってみようと思いました。
大きい順に並び替えるメソッドがあるかもしれないなーと思ったけど、自分で書いた方がプログラミングの練習になると思いました。
以下が実際に書いたコードです。

sort_number = [15,1,93,52,66,31,87,0,42,77,46,24,99,10,19,36,27,4,58,76,2,81,50,102,33,94,20,14,80,82,49,41,12,143,121,7,111,100,60,55,108,34,150,103,109,130,25,54,57,159,136,110,3,167,119,72,18,151,105,171,160,144,85,201,193,188,190,146,210,211,63,207]

x = 0
y = 0

is_complete = False

while not is_complete:
    is_complete = True
    for i in range(len(sort_number) - 1):
        if sort_number[i] < sort_number[i+1]:
            if is_complete==True:
                is_complete=False;
            x = sort_number[i]
            y = sort_number[i+1]
            sort_number[i] = y
            sort_number[i+1] = x

for i in range(len(sort_number)):
    print(sort_number[i], end="")
#実行結果
2112102072011931901881711671601591511501461441431361301211191111101091081051031021009994938785828180777672666360585755545250494642413634333127252420191815141210743210

無駄なところはあるかもしれませんが、自分で考えてやってみました。
やっぱり、自分でコードを書いて解けたらめっちゃ気持ちいいです。

終わったあとに調べてみると、sortメソッドというものがあるらしいです。

0
0
0

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?