티스토리 뷰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import Foundation let money = Int(readLine()!)! let humans = Int(readLine()!)! var temp = [String]() var array = [Int]() for _ in 0..<humans{ temp.append(readLine()!) } for _ in 0..<100{ array.append(0) } for i in temp{ let command = i.split(separator: " ").map { String($0) } let position = Int(command.first!)! let direction = command.last! if(direction == "L"){ for i in 0..<position-1{ if(array[i] == 2){ array[i] = 0 } else { array[i] += 1 } } } else { for i in position..<100{ if(array[i] == 2){ array[i] = 0 } else { array[i] += 1 } } } } var result = [0,0,0] for i in array{ switch(i){ case 0: result[0] += 1 case 1: result[1] += 1 case 2: result[2] += 1 default: break } } for i in result{ print(String.init(format: "%.2f", Double(money) * (Double(i) / 100.0))) } | cs |
String(format:) 함수를 쓰려면 import Foundation을 해주어야 한다.
'Algorithm > Baekjoon Online Judge' 카테고리의 다른 글
10799번 '쇠막대기' (0) | 2018.04.12 |
---|---|
2941번 '크로아티아 알파벳' (0) | 2018.04.08 |
14647번 '준오는 조류혐오야!!' (0) | 2018.02.27 |
14648번 '쿼리 맛보기' (0) | 2018.02.27 |
14646번 '욱제는 결정장애야!!' (0) | 2018.02.27 |
댓글