Created
May 30, 2017 02:22
-
-
Save nattybear/008ead46294e3630107988f9a408200e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| dic1 = { 'zero' : 0, | |
| 'one' : 1, | |
| 'two' : 2, | |
| 'three' : 3, | |
| 'four' : 4, | |
| 'five' : 5, | |
| 'six' : 6, | |
| 'seven' : 7, | |
| 'eight' : 8, | |
| 'nine' : 9, | |
| 'ten' : 10 } | |
| dic2 = { 0 : set('zero'), | |
| 1 : set('one'), | |
| 2 : set('two'), | |
| 3 : set('three'), | |
| 4 : set('four'), | |
| 5 : set('five'), | |
| 6 : set('six'), | |
| 7 : set('seven'), | |
| 8 : set('eight'), | |
| 9 : set('nine'), | |
| 10 : set('ten') } | |
| def func(): | |
| q = input() | |
| q = q.split(' ') | |
| a = dic1[q[0]] | |
| o = q[1] | |
| b = dic1[q[2]] | |
| c = q[4] | |
| d = 0 | |
| if o == '+': | |
| d = add(a, b) | |
| elif o == '-': | |
| d = sub(a, b) | |
| elif o == '*': | |
| d = mul(a, b) | |
| try: | |
| if dic2[d] == set(c): print('Yes') | |
| else: print('No') | |
| except KeyError: | |
| print('No') | |
| def add(a, b): | |
| return a + b | |
| def sub(a, b): | |
| return a - b | |
| def mul(a, b): | |
| return a * b | |
| cnt = int(input()) | |
| for i in range(cnt): | |
| func() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
전체적으로 파이썬 딕셔너리 자료형을 이용함
아나그램 해결을 위해서 파이썬 SET 자료형을 이용
KeyError를 이용해서 예외처리
KeyError가 발생하는 것을 역으로 이용함