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?

More than 1 year has passed since last update.

【Paiza問題集】ループメニュー1/数列の中に何個ある?

Posted at

Paiza問題集

Pythonで回答

ループメニュー1/数列の中に何個ある?

Step01 数列の最大値

"""
数列の最大値
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_max

問題
長さNの数列a(a_1, a_2, .., a_N)が与えられます
この数列の最大値を出力してください
"""

N = int(input())
a = list(map(int, (input().split())))

max = 0
for i in range(N):
    if a[i] >= max:
        max = a[i]

print(max)

Step02 数列の最小値

"""
数列の最小値
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_min

問題
長さNの数列a(a_1, a_2, .., a_N) が与えられます
この数列の最小値を出力してください
"""

N = int(input())
a = list(map(int, (input().split())))

min = 100
for i in range(N):
    if a[i] <= min:
        min = a[i]

print(min)

Step03 数列の何番目にある?

"""
数列の何番目にある?
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_i-th

問題
数列の何番目に1があるか出力してください
出力の末尾には改行を入れてください
"""

N = int(input())
a = list(map(int, (input().split())))

count = 0
for i in range(N):
    count += 1
    if a[i] == 1:
        break

print(count)

Final問題 数列の中に何個ある?

"""
数列の中に何個ある? 
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_count

問題
数列の中に1が何個あるか出力してください
出力の末尾には改行を入れてください
"""

N = int(input())
a = list(map(int, (input().split())))

count = 0
for i in range(N):
    if a[i] == 1:
        count += 1

print(count)
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?