Bibi's DevLog ๐Ÿค“๐ŸŽ

[๋ฐฑ์ค€ 4458] ์ฒซ ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ/์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€์ด Swift

[๋ฐฑ์ค€ 4458] ์ฒซ ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ

๋น„๋น„ bibi 2022. 10. 14. 14:39

4458 ์ฒซ ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ

4458๋ฒˆ: ์ฒซ ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ

  • ์ฒซ ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฌธ์ œ.
  • ์—„์ฒญ ์‰ฌ์šด ๋ฌธ์ œ์ธ๋ฐ 1์‹œ๊ฐ„ ์ •๋„ ์™œ ์•ˆ๋˜์ง€?๋ฅผ ๋ฐ˜๋ณตํ•˜๋‹ค๊ฐ€ ๊ตฌ๊ธ€๋ง์„ ํ†ตํ•ด ์ •๋‹ต ์ฝ”๋“œ๋ฅผ ๋ดค๋‹ค.ใ… 

ํ’€์ด 1 (๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ)

let count = Int(readLine()!)!
var answer: [String] = []
if count <= 0 {
    return
}
(1...count).forEach { _ in
    let input = readLine()!
    let startIndex = input.startIndex
    if input[startIndex].isLowercase {
        print(input[startIndex].uppercased() 
                        + input[input.index(after: startIndex)...input.index(before: input.endIndex)])
    }
    if input[startIndex].isUppercase {
        print(input)
    }
}
  • ์ฒซ ๊ธ€์ž๋ฅผ startIndex๋กœ ๊ฐ€์ ธ์™€์„œ ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊พธ๊ณ , ๋‚˜๋จธ์ง€ ๋ฌธ์ž๋“ค์— ๋ถ™์ด๋Š” ๋ฐฉ์‹์œผ๋กœ ํ’€์ดํ–ˆ๋Š”๋ฐ
  • ๋‚˜๋จธ์ง€ ๋ฌธ์ž๋“ค์„ ์ธ๋ฑ์Šค๋กœ ์ ‘๊ทผํ–ˆ๋‹ค. input[input.index(after: input.startIndex)โ€ฆinput.index(before: input.endIndex)]
  • ์˜ˆ์ œ๋Š” ์ž˜ ๋๋Š”๋ฐ, ์ธ๋ฑ์Šค ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”์ง€ 50%๊นŒ์ง€ ์ฑ„์ ํ•˜๋‹ค๊ฐ€ ๋Ÿฐํƒ€์ž„์—๋Ÿฌ๊ฐ€ ๋‚˜์™”๋‹ค.
  • ๊ทธ๋ž˜์„œ count๊ฐ€ 0์ผ ์ˆ˜ ์žˆ๋‚˜.. ํ•ด์„œ 0 ์ดํ•˜ ๊ฐ’์„ ์˜ˆ์™ธ์ฒ˜๋ฆฌํ–ˆ๋Š”๋ฐ๋„ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐ˜๋ณต๋˜์—ˆ๋‹ค.

ํ’€์ด2 (๊ตฌ๊ธ€๋ง)

์ถœ์ฒ˜ : https://velog.io/@hygge/Swift-PS-1์ฃผ์ฐจ

let count = Int(readLine()!)!
(1...count).forEach { _ in
    var input = readLine()!
    let first = input[input.startIndex].uppercased()
    input.removeFirst()
    print(first + input)
}
  • startIndex๋กœ ๋งจ ์ฒซ ๊ธ€์ž์— ์ ‘๊ทผํ•ด์„œ uppercase๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์€ ๋™์ผ
  • ๋ฌธ์ž์—ด๋„ ๋ฐฐ์—ด์ด๊ธฐ ๋•Œ๋ฌธ์— removeFirst๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค!! ใ… ใ…  ์œ ์šฉํ•˜๊ฒŒ ํ™œ์šฉํ•˜์ž.