feldblume5263 / TIL

Today I Learned
0 stars 0 forks source link

(220917)[개인 공부] 백준(1시간) #33

Closed feldblume5263 closed 2 years ago

feldblume5263 commented 2 years ago

잘해보장~!!

feldblume5263 commented 2 years ago

1157

let inputs = readLine()!.map {
    return String($0).uppercased()
}

var dict = [String : Int]()
for input in inputs {
    if dict[input] != nil {
        dict[input]! += 1
    } else {
        dict[input] = 1
    }
}

let sorted = dict.sorted { $0.value > $1.value }
if sorted.count > 1 {
    if sorted[0].value == sorted[1].value {
        print("?")
    } else {
        print(sorted[0].key)
    }
} else {
    print(sorted[0].key)
}

1152

print(readLine()!.split(separator: " ").count)

2908

let inputs = readLine()!.split(separator: " ").map {String($0)}
let a = Int(String(inputs[0].reversed()))!
let b = Int(String(inputs[1].reversed()))!
print(a > b ? "\(a)" : "\(b)")

5622

let inputs = readLine()!.map{String($0)}
let a = ["ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"]
var sum = 0
for input in inputs {
    sum += (a.firstIndex{$0.contains(Character(input))}! + 3)
}
print(sum)

2941

import Foundation
var inputs = readLine()!
let als = ["c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="]
for al in als {
    inputs = inputs.replacingOccurrences(of: al, with: ".")
}
print(inputs.count)

1316

let n = Int(readLine()!)!
var s = 0
for _ in 0..<n {
    let inputs = readLine()!//.map{String($0)}
    var flag = true
    for input in inputs {
        let iter = (inputs.components(separatedBy: String(input)).count - 1)
        var new = ""
        for _ in 0..<iter {
            new += String(input)
        }
        if !inputs.contains(new) {
            flag = false
        }
    }
    if flag {
        s += 1
    }
}
print(s)