[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค-Lv1] ์Œ์–‘ ๋”ํ•˜๊ธฐ / Python

๐Ÿ“š Problem Solving/Programmers

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์Œ์–‘ ๋”ํ•˜๊ธฐ

์–ด๋–ค ์ •์ˆ˜๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์ •์ˆ˜๋“ค์˜ ์ ˆ๋Œ“๊ฐ’์„ ์ฐจ๋ก€๋Œ€๋กœ ๋‹ด์€ ์ •์ˆ˜ ๋ฐฐ์—ด absolutes์™€ ์ด ์ •์ˆ˜๋“ค์˜ ๋ถ€ํ˜ธ๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ๋‹ด์€ ๋ถˆ๋ฆฌ์–ธ ๋ฐฐ์—ด signs๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์‹ค์ œ ์ •์ˆ˜๋“ค์˜ ํ•ฉ์„ ๊ตฌํ•˜์—ฌ re

programmers.co.kr

import sys

input = sys.stdin.readline
absolutes = list(map(int, input().split()))
signs = list(map(int, input().split()))


def solution(absolutes, signs):
    for i in range(len(signs)):
        if signs[i] == False:
            absolutes[i] *= -1
    return sum(absolutes)


print(solution(absolutes, signs))

 

ํ•ด์„ค

signs์— false์ธ ๊ฒฝ์šฐ์—๋งŒ absolutes ํ•ด๋‹น ์ธ๋ฑ์Šค ๊ฐ’์„ ์Œ์ˆ˜๋กœ ์ทจํ•ด์ค€๋‹ค.

 

์ฒ˜์Œ์— ์ž…์ถœ๋ ฅ ์˜ˆ๋ฅผ ๋ณด๊ณ  "true", "false"๋กœ ์ž…๋ ฅ์ด ๋˜๋Š” ์ค„ ์•Œ์•˜๋Š”๋ฐ boolean์ธ True, False๋กœ ์ž…๋ ฅ์„ ๋ฐ›์•„์•ผํ–ˆ๋‹ค..