Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
18
Help us understand the problem. What are the problem?

posted at

updated at

Organization

# Progateを一通り終えたら次はpaizaだ！

そんな声を聞いたのでやり始めた去年の夏。
Dランクですら回答がままならないのに凹んでた学習中の私。

Aランク目指してたまーにやろうかなと思ったから復習まとめ&これから勉強して行く初学者の方達に少しでも力になれればと、paizaの問題でよく使った入力と出力とかの記法を纏めます。(Bランク相当)

## 標準入力編

##### スペース区切りの数値をリストに
``````30 30 10
``````
``````num_list = [int(i) for i input().split()]
print(num_list)
``````

[30, 30, 10]

##### スペース区切りの数値をそれぞれの変数に
``````30 30 10
``````
``````num1, num2, num3 = list(map(int, input().split()))
print(num1, num2, num3)
``````

30, 30, 10

##### 連続した数値の入力処理
``````3
6
7
8
``````
``````num_list =[ int(input()) for i in range(4)]
print(num_list)
``````

[3, 6, 7, 8]

##### 連続した入力を辞書型に
``````"A" 3
"B" 5
"C" 5
``````
``````num_dic = {}
for i in range(3):
word, num = input().split()
num_dic[word] = int(num)

print(num_dic)

``````

{"A": 1, "B": 2, "C": 3}

##### 多次元配列
``````66737
56173
59414
25469
63955
``````
``````num_list = []

for i in range(5):
nums = list(map(int, input()))
num_list.append(nums)

print(num_list)
``````

[[6, 6, 7, 3, 7], [5, 6, 1, 7, 3], [5, 9, 4, 1, 4], [2, 5, 4, 6, 9], [6, 3, 9, 5, 5]]

## 出力編

##### 辞書型
``````num_dic = {"A": 1, "B": 2, "C": 3}

for word, num in num_dic.items():
print(word, num)

``````

"A", 3
"B", 5
"C", 5

##### 多次元配列

その１

``````num_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

for i in range(3):
for j in range(3):
print(num_list[i][j])

``````

1
2
3
4
5
6
7
8
9

その２

``````num_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

for nums in num_list:
print(nums)
for num in nums:
print(num)

``````

[1, 2, 3]
1
2
3
[4, 5, 6]
4
5
6
[7, 8, 9]
7
8
9

##### 末尾のスペース消せなくて困ってる場合
``````word_list = [["A", "B", "C"], ["D", "E", "F"], ["G", "I", "H"]]

for i in word_list:
print(' '.join(map(str, i)))
``````

A B C
D E F
G I H

## 番外編

##### アルファベットのリスト
``````alpha_list1 = []
alpha_list2 = []
for i,c in enumerate(range(ord('A'),ord('Z')+1)):
alpha_list1.append(chr(c))
print(alpha_list1)
for i,c in enumerate(range(ord('a'),ord('z')+1)):
alpha_list2.append(chr(c))
print(alpha_list2)
``````

(iには０からの数字が入っている。なくても動く)

[['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

##### リストのソート

``````num_list = [3, 4, 2, 1]
num_list.sort()
print(num_list)

``````

[1, 2, 3, 4]

``````num_list = [3, 4, 2, 1]
num_list.sort(reverse=True)
print(num_list)

``````

[4, 3, 2, 1]

Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
18
Help us understand the problem. What are the problem?