백준 기초 . 문자열 문제 모음

HAHAING·2025년 7월 30일

코딩 테스트

목록 보기
9/30

https://codingdodo.tistory.com/94?utm_source=chatgpt.com
-> 백준 코딩 초보 문제집을 참고하였다.

브론즈

11720. 숫자의 합

-> input()으로 받았을때 개행 문자를 제거하기 위해 .strip() 써야함.

#문자열 
#숫자의 합 
import sys 
input = sys.stdin.readline 
n = int(input())
num = input().strip()#이렇게 하면, \n이 남아있어서 에러 
num_list = list(map(int, num))
print(num_list)
print(sum(num_list))
# num_list = map(int, input())
# print(sum(num_list))

9046. 복호화

from collections import Counter 
n = int(input()) 
lst = [] 
for i in range(n): 
	lst.append(input().replace(" ", ""))

for sen in lst: 
	cnt = Counter(sen.lower()) #소문자로 바꾸기 
    if list(cnt.values()).count(max(cnt.values())) > 1
    	print("?")
    else: 
    	for k, v in cnt.items(): 
        	if v == max(cnt.values()): 
            	print(k)

10798. 단어장

import sys 
input = sys.stdin.readline 

words = [list(map(str, input().strip())) for _ in range(5)]
print(words)

for i in range(5): 
	for j in range(5): 
		print(words[j][i], end = "")
        

=> 문제: 리스트에 빈 문자열이 있을때 에러

import sys 
input = sys.stdin.readline 

words = [list(map(str, input().strip())) for _ in range(5)]
#print(words)

for i in range(5): 
	for j in range(5): 
		#해당 인덱스가 존재할때만 
		if i < len(words[j]): 
			print(words[j][i], end = "")
            

1157. 단어 공부

from collections import Counter 
alphas = list(map(str, input().lower()) ) 

cnt = Counter(alphas) 

if list(cnt.values()).count(max(cnt.values())) > 1: 
	print("?")
else: 
	for k, v in cnt.items(): 
    	if v == max(cnt.values()): 
        	print(k.upper())

실버

4659. 비밀번호 발음하기

profile
따뜻한 시선으로 세상을 변화시키는 데이터사이언티스트

0개의 댓글