LoginSignup
0
1

More than 3 years have passed since last update.

【Python】ABC - 093 - Small and Large Integers

Posted at

問題

$A以上B以下$の整数の中で、小さい方からK番目以内であるか、大きい方からK番目以内である整数を昇順ですべて出力する問題。

方針

$A以上B以下$の整数の数が$2K$以上か、未満かで場合分けする。
$2K$未満の場合は、$A以上B以下$の整数を昇順ですべて出力すればいい。

A, B, K = map(int, input().split())
if B-A+1 >= 2*K: # A以上B以下の整数の数が2K以上
    res_list = [i for i in range(A, A+K)] + [i for i in range(B-K+1, B+1)]
else: # A以上B以下の整数の数が2K未満
    res_list = [i for i in range(A, B+1)]
for i in res_list:
    print(i)
0
1
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
1