Henu
개발냥발
Henu
전체 방문자
오늘
어제
  • 분류 전체보기 (411)
    • DevOps (52)
      • Kubernetes (19)
      • Docker (14)
      • AWS (3)
      • Nginx (4)
      • Linux (4)
      • ArgoCD (1)
      • CN (2)
      • NATS (0)
      • Git (5)
    • Back-End (30)
      • Django (18)
      • Spring (5)
      • JPA (1)
      • MSA (5)
    • CS (87)
      • SystemSoftware (20)
      • OS (25)
      • Computer Architecture (16)
      • Network (23)
      • Database (2)
    • Lang (21)
      • Java (9)
      • Python (4)
      • C# (8)
    • Life (12)
    • 블록체인 (2)
    • Algorithm (204)
      • BOJ (160)
      • 프로그래머스 (19)
      • LeetCode (4)
      • SWEA (1)
      • 알고리즘 문제 해결 전략 (8)
      • DS, algorithms (7)
      • Checkio (5)
    • IT (2)

블로그 메뉴

  • GitHub
  • 글쓰기
  • 관리자

공지사항

  • Free!

인기 글

태그

  • django
  • 프로그래머스
  • 다이나믹 프로그래밍
  • Network
  • 백트래킹
  • docker
  • Kubernetes
  • boj
  • DFS
  • BFS

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Henu

개발냥발

[Checkio] Electronic station. Surjection Strings
Algorithm/Checkio

[Checkio] Electronic station. Surjection Strings

2020. 6. 11. 17:21

You need to check that the 2 given strings are isometric. This means that a character from one string can become a match for characters from another string.

One character from one string can correspond only to one character from another string. Two or more characters of one string can correspond to one character of another string, but not vice versa.

Input: Two arguments. Both strings.

Output: Boolean.

 

str1 과 str2 의 구성요소들이 서로 상응해야한다

 

1
2
3
4
5
6
7
8
9
10
11
12
13
def isometric_strings(str1: str, str2: str) -> bool:
    rel = {}
    temp = ""
    if len(str1) != len(str2): # 길이가 다르면 false
        return False
    else:
        for index, e in enumerate(str1): # 문자와 해당 문자의 인덱스 반환
            if e in rel.keys():
                temp += rel[e]
            else:
                rel[e] = str2[index]
                temp += rel[e]
    return temp == str2
cs

학교 수업에서 배웠던 문자열 접합과 enumerate함수를 사용했다!

 

True가 되는 문자열을 만들고(temp), 그게 str2와 같다면 True를 반환하도록 만들었다

 

서로 상응하는 자료를 만들 때 딕셔너리는 key 자체로 바로 값을 얻을 수 있어서 정말 편한것 같다

 

'Algorithm > Checkio' 카테고리의 다른 글

[Checkio] Scientific Expedition. Sum by Type  (0) 2020.06.17
[Checkio] Electronic station. Digits Multiplication  (0) 2020.06.09
[Checkio] HOME. Bigger Price  (0) 2020.06.09
[Checkio] HOME. Sort Array by Element Frequency  (0) 2020.06.08
    'Algorithm/Checkio' 카테고리의 다른 글
    • [Checkio] Scientific Expedition. Sum by Type
    • [Checkio] Electronic station. Digits Multiplication
    • [Checkio] HOME. Bigger Price
    • [Checkio] HOME. Sort Array by Element Frequency

    티스토리툴바