반응형
BOJ 2577 with Swift
https://www.acmicpc.net/problem/2577
import Foundation
struct Q2577 {
static func input() -> String {
if let a = Int(readLine()!) , let b = Int(readLine()!) , let c = Int(readLine()!) {
return String(a * b * c)
}
return ""
}
static func main() {
var count = ""
let number = input()
// countZero
count += "\(self.matchZero(number))"
// matchNumber
for i in 1..<10{
let str = String(i)
let char = Character(str)
count += "\(matchNumber(char, number))"
}
self.printCount(count)
}
static func printCount(_ count:String) {
for c in count {
print(c)
}
}
static func matchNumber(_ target:Character , _ numbers:String) -> Int {
var count = 0
for number in numbers {
if target == number {
count += 1
}
}
return count
}
static func matchZero(_ numbers:String) -> Int {
var count = 0
for number in numbers {
if number == "0" {
count += 1
}
}
return count
}
}
Q2577.main()
반응형
'BOJ알고리즘' 카테고리의 다른 글
BOJ 11654 with Swift (0) | 2018.09.02 |
---|---|
BOJ 10809 with Swift (0) | 2018.09.02 |
BOJ 10039 with Swift (0) | 2018.09.02 |
BOJ 8958 with Swift (0) | 2018.09.02 |
BOJ 2920 with Swift (0) | 2018.09.02 |