백준 - 1076 저항 - Swift

AekT·2021년 11월 13일
0
post-thumbnail

백준 1076 저항

문제 : https://www.acmicpc.net/problem/1076

배열을 만들고 인덱스로 저항의 값을 구한다음 3번째 저항만큼 0을 += 해주고 Int로 바꾸면 출력도 정상적으로 된다.

Code :

let arr = Array(arrayLiteral: "black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white")
let one = readLine()!
let two = readLine()!
var three = "\(arr.firstIndex(of: one)!)\(arr.firstIndex(of: two)!)"
let input = readLine()!
for i in 0..<Int(exactly: arr.firstIndex(of: input)!)!{
    three += "0"
}
print(UInt64(three)!)
profile
으악

0개의 댓글