BOJ 1032 명령 프롬프트
# 풀이
모든 문자열의 길이가 같고.
다른 문자가 온다면 그것만 ? 로 바꿔주면 된다.
# 코드
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
def data1(n): | |
if '\x1a' in n: n = n.replace('\x1a','') | |
if '\n' in n: n = n.replace('\n','') | |
return n | |
import sys | |
input = sys.stdin.readlines() | |
input = list(map(data1,input)) | |
ans = '' | |
str_len = len(input[1]) | |
# 돌면서 길이를 재는데 | |
for idx in range(str_len): | |
# 처음에 빈칸을 더한다(파일이름은 소문자와 점으로 되어있음) | |
ans += ' ' | |
for tmp in input[1:]: | |
# 처음 경우 | |
if ans[idx] == ' ': | |
ans = ans.replace(' ',tmp[idx]) | |
else: # 두번째부터 | |
if tmp[idx] != ans[idx]: | |
ans = ans[:-1] + '?' | |
break | |
print(ans) |
풀이가 좀 긴것 같다
```python
n=int(input())
l=list(input())
m=len(l)
for i in range(n-1):
nl=list(input())
for j in range(m):
if l[j]!=nl[j]:
l[j]='?'
print(''.join(l))
```
어쨌든 다르면 ?로 바꾸면 된다.
처음에 빈칸을 더할 필요가 없이 print 끝부분에 end = '' 을 이용해서 다를경우엔 ? 를 출력해주는 풀이도 가능해보인다.
0 댓글