BAEKJOON : 11720, 10809, 2675, 1157, 2908, 5622
No. 11720
1. Problem
2. My Solution
import sys
n = sys.stdin.readline().strip()
result = eval('+'.join(sys.stdin.readline().strip()))
print(result)
No. 10809
1. Problem
2. My Solution
ord()関数を用いて
import sys
s = sys.stdin.readline().strip()
result = []
for i in range(ord('a'), ord('z')+1):
try:
result.append(s.index(chr(i)))
except:
result.append(-1)
for i in range(len(result)):
print(result[i], end=' ')
import sys
word = sys.stdin.readline().strip()
alphabet = [-1] * 26
for i in word:
alphabet[ord(i)-97] = word.index(i)
print(' '.join(map(str,alphabet)))
3. Learned No. 2675
1. Problem
2. My Solution
import sys
n = int(sys.stdin.readline().strip())
for i in range(n):
rep, str = sys.stdin.readline().strip().split()
result = ""
for j in range(len(str)):
result += (str[j]* int(rep))
print(result)
3. Others' Solutions for in文を使用してに直接アクセスし、[]インデックス演算子を使用して
import sys
n = int(sys.stdin.readline().strip())
for i in range(n):
rep, str = sys.stdin.readline().strip().split()
result = ""
for j in str:
result += j * int(rep)
print(result)
4. Learned No. 1157
1. Problem
2. My Solution
import sys
word = [char.lower() for char in sys.stdin.readline().strip()]
alpha_count = []
for i in range(ord('a'), ord('z')+1):
alpha_count.append(word.count(chr(i)))
if alpha_count.count(max(alpha_count)) > 1 :
print("?")
else:
print(chr(alpha_count.index(max(alpha_count))+97).upper())
3. Others' Solutions -入力した文字列を直接入力します.upper()関数の適用
mport sys
word = sys.stdin.readline().upper()
alpha_count = []
for i in range(ord('A'), ord('Z')+1):
alpha_count.append(word.count(chr(i)))
if alpha_count.count(max(alpha_count)) > 1 :
print("?")
else:
print(chr(alpha_count.index(max(alpha_count))+65))
-setデータ型を使用して重複するアルファベットを削除し、リストに再挿入して判断する
-
import sys
word = sys.stdin.readline().strip().upper()
char_list = list(set(word))
alpha_count = []
for char in char_list:
alpha_count.append(word.count(char))
if alpha_count.count(max(alpha_count)) > 1 :
print("?")
else:
print(char_list[alpha_count.index(max(alpha_count))])
4. Learned No. 2908
1. Problem
2. My Solution
import sys
a,b = sys.stdin.readline().strip().split()
a,b = a[::-1], b[::-1]
if int(a) > int(b):
print(a)
else:
print(b)
3. Others' Solutions print(max(input()[::-1].split()))
4. Learned 文字列[:-1]を使用して
No. 2908
1. Problem
2. My Solution
import sys
alpha_num = [['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']]
word = list(sys.stdin.readline().strip())
total_time = 0
for i in word:
for j in range(len(alpha_num)):
if i in alpha_num[j]:
total_time += j+3
print(total_time)
4. Learned 以下のコードは
import sys
alpha_num = [['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']]
word = list(sys.stdin.readline().strip())
total_time = 0
for i in word:
for j in range(len(alpha_num)):
if i in alpha_num[j]:
total_time += j+3
print(total_time)
Reference
この問題について(BAEKJOON : 11720, 10809, 2675, 1157, 2908, 5622), 我々は、より多くの情報をここで見つけました https://velog.io/@codren/BAEKJOON-11720-10809-2675テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol