-
[백준] 1032 - 명령 프롬프트 (python)Problem Solving/Python 2023. 7. 7. 15:50반응형
https://www.acmicpc.net/problem/1032
1032번: 명령 프롬프트
첫째 줄에 파일 이름의 개수 N이 주어진다. 둘째 줄부터 N개의 줄에는 파일 이름이 주어진다. N은 50보다 작거나 같은 자연수이고 파일 이름의 길이는 모두 같고 길이는 최대 50이다. 파일이름은
www.acmicpc.net
포인트
문자열의 갯수도 50개 이하이고 글자의 길이도 50이하라니 무식하게 하나씩 확인해가면서 풀어도 무방하다. 무식하게 풀자
코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters# 파일명 갯수 입력받고 n = int(input()) # 파일 명들도 입력받는다 file_names = [] for _ in range(n): file_names.append(input()) answer = '' # 파일 이름 길이는 모두 같다고 하니 첫 글자 기준으로 한글자씩 반복하며 for i in range(len(file_names[0])): character = '' # 모든 글자들을 확인하는데 for file_name in file_names: # 첫글자이거나 저장해둔 문자와 같으면 그 문자로 갱신 if character == '' or character == file_name[i]: character = file_name[i] # 만약 하나라도 저장된 글자와 다르면 그 인덱스의 문자는 ? else: character = '?' break # 정답에 한 글자씩 추가 answer += character print(answer) 반응형'Problem Solving > Python' 카테고리의 다른 글
[백준] 1075 - 나누기 (python) (0) 2023.07.10 [백준] 1037 - 약수 (python) (0) 2023.07.07 [백준] 1018 - 체스판 다시 칠하기 (python) (0) 2023.07.07 [백준] 1012 - 유기농 배추 (dfs 풀이) (python) (0) 2023.07.07 [프로그래머스] 나머지가 1이 되는 수 찾기 (python) (0) 2023.07.05