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.

プログラミングコンテストチャレンジブックをpythonで解く(1-6)

Posted at
test.py

#三角形の最大の周長を求める。
#三角形を作れない場合は0を出力する。

list = [2,3,4,5,10]
line_sum = 0

for i in range(len(list)):
    for j in range(i+1, len(list)):
        for k in range(j+1, len(list)):
            max_num = max([list[i], list[j], list[k]])
            other_sum = sum([list[i], list[j], list[k]]) - max_num
            if other_sum - max_num > 0:
                if line_sum < sum([list[i], list[j], list[k]]):
                    line_sum = sum([list[i], list[j], list[k]])
                    
print(line_sum) #12

プログラミングコンテストチャレンジブック-第2版-~問題解決のアルゴリズム活用力とコーディングテクニック

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?