Part4.9_자료구조(스택,큐,해쉬,힙)_아나그램_리스트 해쉬로 풀기

Eugenius1st·2022년 1월 19일
0

Python_algorithm

목록 보기
26/83

아나그램_리스트 해쉬로 풀기

리스트로 풀라고 요구할 수도 있다. 아스키 넘버로 풀어보자
알파벳 52개로..

C++ 처럼 풀기

import sys
sys.stdin = open("input.txt", "rt")
# 딕셔너리 사용. index를 int로만 사용하는list와 다르게 
# index의 값으로 str, 단어 다 가능하다.

a = input()
b=input()
str1=[0]*52
str2=[0]*52
# 소문자는 65~90
# 대문자는 97~122 (-65,-71해주어 인덱스번호 0부터 활용)

for x in a:
    if x.isupper(): # 대문자인 아스키넘버만
        str1[ord(x)-65]+=1 #아스키 넘버로 변환
    else:
        str1[ord(x)-71]+=1 #아스키 넘버로 변환
for x in b:
    if x.isupper(): # 대문자인 아스키넘버만
        str2[ord(x)-65]+=1 #아스키 넘버로 변환
    else:
        str2[ord(x)-71]+=1 #아스키 넘버로 변환
for i in range(52):
    if str1[i] != str2[i]:
        print("NO")
        break
else:
    print("YES")
profile
최강 프론트엔드 개발자가 되고싶은 안유진 입니다

0개의 댓글