๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm/Codeup

[Codeup] ์ฝ”๋“œ์—… ๊ธฐ์ดˆ 100์ œ Python #6052 ~ #6060

 

 

#6052 - ์ •์ˆ˜ ์ž…๋ ฅ๋ฐ›์•„ ์ฐธ ๊ฑฐ์ง“ ํ‰๊ฐ€ํ•˜๊ธฐ 

a = int(input())
print(bool(a))
๋ถ„์„ > bool(a)๋ฅผ ์ ์œผ๋ฉด 0์€ False๋กœ ๊ทธ ์ด์™ธ์˜ ๊ฐ’๋“ค์€ True๊ฐ€ ๋œ๋‹ค. 

 

 

#6053 - ์ฐธ ๊ฑฐ์ง“ ๋ฐ”๊พธ๊ธฐ 

a = bool(int(input()))
print(not a)
๋ถ„์„ > ์œ„์˜ a์˜ ๊ฒฝ์šฐ input -> int -> bool ์ˆœ์œผ๋กœ ์ฒ˜๋ฆฌ๋˜๋ฉฐ ์ฐธ ๋˜๋Š” ๊ฑฐ์ง“์˜ ๋…ผ๋ฆฌ๊ฐ’์„ ์—ญ(๋ฐ˜๋Œ€)์œผ๋กœ ๋ฐ”๊พธ๊ธฐ ์œ„ํ•ด์„œ not ์˜ˆ์•ฝ์–ด(reserved word, keyword)๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

 

 

#6054 - ๋‘˜๋‹ค ์ฐธ์ผ ๊ฒฝ์šฐ๋งŒ ์ฐธ ์ถœ๋ ฅํ•˜๊ธฐ 

a,b = input().split()
print(bool(int(a)) and bool(int(b)))
๋ถ„์„ > and ์˜ˆ์•ฝ์–ด๋Š” ์ฃผ์–ด์ง„ ๋‘ ๋ถˆ ๊ฐ’์ด ๋ชจ๋‘ True ์ผ ๋•Œ์—๋งŒ True ๋กœ ๊ณ„์‚ฐํ•˜๊ณ , ๋‚˜๋จธ์ง€ ๊ฒฝ์šฐ๋Š” False ๋กœ ๊ณ„์‚ฐํ•œ๋‹ค.

 

 

#6055 - ํ•˜๋‚˜๋ผ๋„ ์ฐธ์ด๋ฉด ์ฐธ ์ถœ๋ ฅํ•˜๊ธฐ 

a,b = input().split()
print(bool(int(a)) or bool(int(b)))
๋ถ„์„ > or ์˜ˆ์•ฝ์–ด๋Š” ์ฃผ์–ด์ง„ ๋‘ ๋ถˆ ๊ฐ’ ์ค‘์— ํ•˜๋‚˜๋ผ๋„ True ๊ฐ€ ์žˆ์œผ๋ฉด True ๋กœ ๊ณ„์‚ฐํ•œ๋‹ค.

 

 

 

#6056 - ์ฐธ/๊ฑฐ์ง“์ด ์„œ๋กœ ๋‹ค๋ฅผ ๋•Œ๋งŒ ์ฐธ ์ถœ๋ ฅํ•˜๊ธฐ 

a,b = input().split()
c = bool(int(a))
d = bool(int(b))
print((c and (not d)) or (d and (not c)))

 

 

#6057 - ์ฐธ/๊ฑฐ์ง“์ด ์„œ๋กœ ๊ฐ™์„ ๋•Œ๋งŒ ์ฐธ ์ถœ๋ ฅํ•˜๊ธฐ 

a,b = input().split()
c = bool(int(a))
d = bool(int(b))
print((c or (not d)) and (d or (not c)))

 

 

#6058 - ๋‘˜ ๋‹ค ๊ฑฐ์ง“์ผ ๊ฒฝ์šฐ๋งŒ ์ฐธ ์ถœ๋ ฅํ•˜๊ธฐ 

a,b = input().split()
c = bool(int(a))
d = bool(int(b))
print((not c) and (not d))

 

 

#6059 - ๋น„ํŠธ๋‹จ์œ„๋กœ NOT ํ•˜์—ฌ ์ถœ๋ ฅํ•˜๊ธฐ 

a = int(input())
print(~a)
๋ถ„์„ > ์ปดํ“จํ„ฐ์— ์ €์žฅ๋˜๋Š” ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋“ค์€ 2์ง„์ˆ˜๋กœ ์ €์žฅ์ด ๋œ๋‹ค. ์–‘์˜ ์ •์ˆ˜๋Š” 2์ง„์ˆ˜ ํ˜•ํƒœ๋กœ ๋ฐ”๋€Œ์–ด ์ €์žฅ๋˜๊ณ , ์Œ์˜ ์ •์ˆ˜๋Š” 2์˜ ๋ณด์ˆ˜ ํ‘œํ˜„ ๋ฐฉ๋ฒ•์œผ๋กœ ์ €์žฅ๋œ๋‹ค. ๊ฐ„๋‹จํžˆ ํ‘œํ˜„ํ•˜๋ฉด ~n = -n - 1 ์ด์™€ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. 

 

 

#6060 - ๋น„ํŠธ๋‹จ์œ„๋กœ and ํ•˜์—ฌ ์ถœ๋ ฅํ•˜๊ธฐ 

a,b = map(int,input().split())
print(a & b)
๋ถ„์„ > &๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 2์ง„์ˆ˜ ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜๋œ ๊ฐ’ ์ค‘์— ๋‘˜๋‹ค 1์ธ ๊ฒฝ์šฐ๋งŒ 1๋กœ ๋ฐ”๋€Œ๊ฒŒ ๋œ ๊ฐ’์„ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.