Swift PS 1์ฃผ์ฐจ ๐Ÿน

์„ ์ฃผยท2022๋…„ 4์›” 24์ผ
0

Swift PS

๋ชฉ๋ก ๋ณด๊ธฐ
1/3

๐Ÿ“ง 2675 ๋ฌธ์ž์—ด ๋ฐ˜๋ณต

๐Ÿ“Œ ๋ฌธ์ œ

๋ฌธ์ž์—ด S๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ํ›„์—, ๊ฐ ๋ฌธ์ž๋ฅผ R๋ฒˆ ๋ฐ˜๋ณตํ•ด ์ƒˆ ๋ฌธ์ž์—ด P๋ฅผ ๋งŒ๋“  ํ›„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ฆ‰, ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ R๋ฒˆ ๋ฐ˜๋ณตํ•˜๊ณ , ๋‘ ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ R๋ฒˆ ๋ฐ˜๋ณตํ•˜๋Š” ์‹์œผ๋กœ P๋ฅผ ๋งŒ๋“ค๋ฉด ๋œ๋‹ค. S์—๋Š” QR Code "alphanumeric" ๋ฌธ์ž๋งŒ ๋“ค์–ด์žˆ๋‹ค.

QR Code "alphanumeric" ๋ฌธ์ž๋Š” 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ$%*+-./: ์ด๋‹ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T(1 โ‰ค T โ‰ค 1,000)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ๋ฐ˜๋ณต ํšŸ์ˆ˜ R(1 โ‰ค R โ‰ค 8), ๋ฌธ์ž์—ด S๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด ์ฃผ์–ด์ง„๋‹ค. S์˜ ๊ธธ์ด๋Š” ์ ์–ด๋„ 1์ด๋ฉฐ, 20๊ธ€์ž๋ฅผ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

์ถœ๋ ฅ

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์— ๋Œ€ํ•ด P๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1

2
3 ABC
5 /HTP

์˜ˆ์ œ ์ถœ๋ ฅ 1

AAABBBCCC
/////HHHHHTTTTTPPPPP

๐Ÿ“Œ ํ’€์ด

๐Ÿ’ฌ Code

let n = Int(readLine()!)!

for _ in 0..<n {
  let input = readLine()!.split(separator:" ")
  let num = Int(String(input[0]))!
  let string = input[1]

  var result = ""

  for char in string {
    let repeated = String(repeating: char, count: num)
    result += repeated
  }

  print(result)
}

๐Ÿ’ก Comment

init(repeating: count: ) ๊ตฌ๋ฌธ์œผ๋กœ ๋ฌธ์ž์—ด๊ณผ ๋ฐฐ์—ด์„ ์ดˆ๊ธฐํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค.

// a๋ฅผ 4๋ฒˆ ๋ฐ˜๋ณตํ•˜๋Š” ๋ฌธ์ž์—ด์„ ๋งŒ๋“ค์–ด๋ณด์ž
let tmp = String(repeating: "a", count: 4)
print(tmp) // aaaa

// 0์„ 10๋ฒˆ ๋ฐ˜๋ณตํ•˜๋Š” ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด๋ณด์ž
let dict = [Int](repeating: 0, count: 10)
print(dict) // [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]



๐Ÿ“ง 1157 ๋‹จ์–ด ๊ณต๋ถ€

๐Ÿ“Œ ๋ฌธ์ œ

์•ŒํŒŒ๋ฒณ ๋Œ€์†Œ๋ฌธ์ž๋กœ ๋œ ๋‹จ์–ด๊ฐ€ ์ฃผ์–ด์ง€๋ฉด, ์ด ๋‹จ์–ด์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋œ ์•ŒํŒŒ๋ฒณ์ด ๋ฌด์—‡์ธ์ง€ ์•Œ์•„๋‚ด๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๋‹จ, ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ์•ŒํŒŒ๋ฒณ ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๋‹จ์–ด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ๋‹จ์–ด์˜ ๊ธธ์ด๋Š” 1,000,000์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— ์ด ๋‹จ์–ด์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋œ ์•ŒํŒŒ๋ฒณ์„ ๋Œ€๋ฌธ์ž๋กœ ์ถœ๋ ฅํ•œ๋‹ค. ๋‹จ, ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋œ ์•ŒํŒŒ๋ฒณ์ด ์—ฌ๋Ÿฌ ๊ฐœ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ?๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1

Mississipi

์˜ˆ์ œ ์ถœ๋ ฅ 1

?

์˜ˆ์ œ ์ž…๋ ฅ 2

zZa

์˜ˆ์ œ ์ถœ๋ ฅ 2

Z

์˜ˆ์ œ ์ž…๋ ฅ 3

z

์˜ˆ์ œ ์ถœ๋ ฅ 3

Z

์˜ˆ์ œ ์ž…๋ ฅ 4

baaa

์˜ˆ์ œ ์ถœ๋ ฅ 4

A

๐Ÿ“Œ ํ’€์ด

๐Ÿ’ฌ Code

var word = readLine()!.uppercased()
var dict = [Character:Int]()
var max = 0
var maxWord = [Character]()

for i in word {
  if dict[i] == nil {
    dict[i] = 1
  } else {
    dict[i]! += 1
  }
}

for (key, value) in dict {
  if value > max {
    max = value
    maxWord = [key]
  } else if value == max {
    maxWord.append(key)
  }
}

if maxWord.count > 1 {
  print("?")
} else {
  print(String(maxWord))
}

๐Ÿ’ก Comment

๋„ˆ๋ฌด,, ํŒŒ์ด์ฌ๊ฐ™์ด ํ’€์—ˆ๋‹ค,,^^




๐Ÿ“ง 1427 ์†ŒํŠธ์ธ์‚ฌ์ด๋“œ

๐Ÿ“Œ ๋ฌธ์ œ

๋ฐฐ์—ด์„ ์ •๋ ฌํ•˜๋Š” ๊ฒƒ์€ ์‰ฝ๋‹ค. ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง€๋ฉด, ๊ทธ ์ˆ˜์˜ ๊ฐ ์ž๋ฆฌ์ˆ˜๋ฅผ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด๋ณด์ž.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ์ •๋ ฌํ•˜๋ ค๊ณ  ํ•˜๋Š” ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 1,000,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค.

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— ์ž๋ฆฌ์ˆ˜๋ฅผ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1

2143

์˜ˆ์ œ ์ถœ๋ ฅ 1

4321

์˜ˆ์ œ ์ž…๋ ฅ 2

999998999

์˜ˆ์ œ ์ถœ๋ ฅ 2

999999998

์˜ˆ์ œ ์ž…๋ ฅ 3

61423

์˜ˆ์ œ ์ถœ๋ ฅ 3

64321

์˜ˆ์ œ ์ž…๋ ฅ 4

500613009

์˜ˆ์ œ ์ถœ๋ ฅ 4

965310000

๐Ÿ“Œ ํ’€์ด

๐Ÿ’ฌ Code

var n = readLine()!.map { Int(String($0))! }
n.sort(by: >)

for i in n {
  print(i, terminator: "")
}

๐Ÿ’ก Comment

map ๊ณ ์ฐจํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด Int ํƒ€์ž…์˜ ๋ฐฐ์—ด๋กœ ์ž…๋ ฅ์„ ๋ฐ›๊ณ , ์ •๋ ฌ์„ ์œ„ํ•ด sort๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค.

  • ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ n.sort(by: <)
  • ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ n.sort(by: >)

print(terminator: "")๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ถœ๋ ฅ ๋๋ถ€๋ถ„์˜ ์ค„๋ฐ”๊ฟˆ์ด ์ œ๊ฑฐ๋œ๋‹ค.
print(terminator: " ") ์š”๋ ‡๊ฒŒ ์“ฐ๋ฉด ์ถœ๋ ฅ ๋๋ถ€๋ถ„์ด ์ค„๋ฐ”๊ฟˆ ๋Œ€์‹  ๋„์–ด์“ฐ๊ธฐ๊ฐ€ ๋œ๋‹ค.




๐Ÿ“ง 10610 30

๐Ÿ“Œ ๋ฌธ์ œ

์–ด๋Š ๋‚ , ๋ฏธ๋ฅด์ฝ”๋Š” ์šฐ์—ฐํžˆ ๊ธธ๊ฑฐ๋ฆฌ์—์„œ ์–‘์ˆ˜ N์„ ๋ณด์•˜๋‹ค. ๋ฏธ๋ฅด์ฝ”๋Š” 30์ด๋ž€ ์ˆ˜๋ฅผ ์กด๊ฒฝํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ๊ทธ๋Š” ๊ธธ๊ฑฐ๋ฆฌ์—์„œ ์ฐพ์€ ์ˆ˜์— ํฌํ•จ๋œ ์ˆซ์ž๋“ค์„ ์„ž์–ด 30์˜ ๋ฐฐ์ˆ˜๊ฐ€ ๋˜๋Š” ๊ฐ€์žฅ ํฐ ์ˆ˜๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์–ดํ•œ๋‹ค.

๋ฏธ๋ฅด์ฝ”๋ฅผ ๋„์™€ ๊ทธ๊ฐ€ ๋งŒ๋“ค๊ณ  ์‹ถ์–ดํ•˜๋Š” ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ.

์ž…๋ ฅ

N์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. N๋Š” ์ตœ๋Œ€ 10^5๊ฐœ์˜ ์ˆซ์ž๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์œผ๋ฉฐ, 0์œผ๋กœ ์‹œ์ž‘ํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ถœ๋ ฅ

๋ฏธ๋ฅด์ฝ”๊ฐ€ ๋งŒ๋“ค๊ณ  ์‹ถ์–ดํ•˜๋Š” ์ˆ˜๊ฐ€ ์กด์žฌํ•œ๋‹ค๋ฉด ๊ทธ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋ผ. ๊ทธ ์ˆ˜๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, -1์„ ์ถœ๋ ฅํ•˜๋ผ.

์˜ˆ์ œ ์ž…๋ ฅ 1

30

์˜ˆ์ œ ์ถœ๋ ฅ 1

30

์˜ˆ์ œ ์ž…๋ ฅ 2

102

์˜ˆ์ œ ์ถœ๋ ฅ 2

210

์˜ˆ์ œ ์ž…๋ ฅ 3

2931

์˜ˆ์ œ ์ถœ๋ ฅ 3

-1

์˜ˆ์ œ ์ž…๋ ฅ 4

80875542

์˜ˆ์ œ ์ถœ๋ ฅ 4

88755420

๐Ÿ“Œ ํ’€์ด

๐Ÿ’ฌ Code

let n = readLine()!.sorted(by: >)
let array = n.map { Int(String($0))! }
let sum = array.reduce(0, +)

if n.contains("0") && sum%3 == 0 {
    print(String(n))
} else {
    print(-1)
}

๐Ÿ’ก Comment

30์˜ ๋ฐฐ์ˆ˜๊ฐ€ ๋˜๋ ค๋ฉด 10์˜ ๋ฐฐ์ˆ˜์ด์ž 3์˜ ๋ฐฐ์ˆ˜์ด๋ฉด ๋œ๋‹ค.

  • ์ˆซ์ž๋ฅผ ์ •๋ ฌํ•˜์—ฌ 10์˜ ๋ฐฐ์ˆ˜๋กœ ๋งŒ๋“ค๊ณ  ์‹ถ๋‹ค๋ฉด, ์›๋ณธ ์ˆซ์ž์— 0์ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.
  • ์ˆซ์ž๋ฅผ ์ •๋ ฌํ•˜์—ฌ 3์˜ ๋ฐฐ์ˆ˜๋กœ ๋งŒ๋“ค๊ณ  ์‹ถ๋‹ค๋ฉด, ์›๋ณธ ์ˆซ์ž์˜ ๊ฐ ์ž๋ฆฌ์˜ ์ˆ˜์˜ ํ•ฉ์ด 3์˜ ๋ฐฐ์ˆ˜์ด๋ฉด ๋œ๋‹ค.
    ๊ฐ€๋ น 8+0+8+7+5+5+4+2=39=3์˜ ๋ฐฐ์ˆ˜์ด๋ฏ€๋กœ 80875542๋Š” 3์˜ ๋ฐฐ์ˆ˜์ด๋‹ค.

์œ„์˜ ๋‘ ์กฐ๊ฑด์„ ๋ชจ๋‘ ์ถฉ์กฑํ•œ๋‹ค๋ฉด
์›๋ณธ ์ˆซ์ž๋ฅผ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋ฉด ์ •๋‹ต์ด ๋œ๋‹ค.

๊ฐ ์ž๋ฆฌ์˜ ์ˆ˜์˜ ํ•ฉ์€ recude ๊ณ ์ฐจํ•จ์ˆ˜๋กœ ๊ตฌํ–ˆ๋‹ค.

  • array.reduce(0, +)

์›๋ณธ ์ˆซ์ž์— 0์ด ์žˆ๋Š”์ง€๋Š” contains๋กœ ๊ตฌํ–ˆ๋‹ค.

  • n.contains("0")
  • n.contains("01")์ฒ˜๋Ÿผ ์—ฌ๋Ÿฌ ๊ธ€์ž์˜ ํฌํ•จ ์—ฌ๋ถ€๋ฅผ ์•Œ๊ณ  ์‹ถ๋‹ค๋ฉด import Foundation์„ ํ•ด์ฃผ์–ด์•ผ ๋™์ž‘ํ•œ๋‹ค.



๐Ÿ“ง 11721 ์—ด ๊ฐœ์”ฉ ๋Š์–ด ์ถœ๋ ฅํ•˜๊ธฐ

๐Ÿ“Œ ๋ฌธ์ œ

์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž์™€ ๋Œ€๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๊ธธ์ด๊ฐ€ N์ธ ๋‹จ์–ด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

ํ•œ ์ค„์— 10๊ธ€์ž์”ฉ ๋Š์–ด์„œ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ๋‹จ์–ด๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‹จ์–ด๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž์™€ ๋Œ€๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ธธ์ด๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. ๊ธธ์ด๊ฐ€ 0์ธ ๋‹จ์–ด๋Š” ์ฃผ์–ด์ง€์ง€ ์•Š๋Š”๋‹ค.

์ถœ๋ ฅ

์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง„ ๋‹จ์–ด๋ฅผ ์—ด ๊ฐœ์”ฉ ๋Š์–ด์„œ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ถœ๋ ฅํ•œ๋‹ค. ๋‹จ์–ด์˜ ๊ธธ์ด๊ฐ€ 10์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋Š” ๋งˆ์ง€๋ง‰ ์ค„์—๋Š” 10๊ฐœ ๋ฏธ๋งŒ์˜ ๊ธ€์ž๋งŒ ์ถœ๋ ฅํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1

BaekjoonOnlineJudge

์˜ˆ์ œ ์ถœ๋ ฅ 1

BaekjoonOn
lineJudge

์˜ˆ์ œ ์ž…๋ ฅ 2

OneTwoThreeFourFiveSixSevenEightNineTen

์˜ˆ์ œ ์ถœ๋ ฅ 2

OneTwoThre
eFourFiveS
ixSevenEig
htNineTen

๐Ÿ“Œ ํ’€์ด

๐Ÿ’ฌ Code

var string = readLine()!
var cnt = 0

for char in string {
  if cnt < 10 {
    cnt += 1
  } else if cnt == 10 {
    cnt = 1
    print("")
  }
  print(char, terminator: "")
}

๐Ÿ’ก Comment

ํ•œ ์ค„์˜ ์‹œ์ž‘์— cnt๊ฐ€ 1์ด ๋˜๊ณ , ํ•œ ๊ธ€์ž ์ถœ๋ ฅํ•  ๋•Œ๋งˆ๋‹ค cnt๋ฅผ ๋Š˜๋ฆฌ๋‹ค๊ฐ€ ํ•œ ์ค„์— 10๊ฐœ๊ฐ€ ๋ชจ๋‘ ์ถœ๋ ฅ๋์œผ๋ฉด print("")๋กœ ์ค„๋ฐ”๊ฟˆํ•ด ๋‹ค์Œ ์ค„๋กœ ๋„˜์–ด๊ฐ„๋‹ค.




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

๐Ÿ“Œ ๋ฌธ์ œ

๋ฌธ์žฅ์„ ์ฝ์€ ๋’ค, ์ค„์˜ ์ฒซ ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊พธ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ์ค„์˜ ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ N๊ฐœ์˜ ์ค„์—๋Š” ๋ฌธ์žฅ์ด ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ๋ฌธ์žฅ์— ๋“ค์–ด์žˆ๋Š” ๊ธ€์ž์˜ ์ˆ˜๋Š” 30์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. ๋ชจ๋“  ์ค„์˜ ์ฒซ ๋ฒˆ์งธ ๊ธ€์ž๋Š” ์•ŒํŒŒ๋ฒณ์ด๋‹ค.

์ถœ๋ ฅ

๊ฐ ์ค„์˜ ์ฒซ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊พผ๋’ค ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1

5
powdered Toast Man
skeletor
Electra Woman and Dyna Girl
she-Ra Princess of Power
darth Vader

์˜ˆ์ œ ์ถœ๋ ฅ 1

Powdered Toast Man
Skeletor
Electra Woman and Dyna Girl
She-Ra Princess of Power
Darth Vader

๐Ÿ“Œ ํ’€์ด

๐Ÿ’ฌ Code

let n = Int(String(readLine()!))!

for _ in 0..<n {
  var input = readLine()!
  let upper = input[input.startIndex].uppercased()
  input.removeFirst(1)
  print(upper + input)
}

๐Ÿ’ก Comment

ํŒŒ์ด์ฌ์œผ๋กœ ๋ฌธ์ž์—ด ๋ฌธ์ œ ํ’€๋‹ค๊ฐ€ ์Šค์œ„ํ”„ํŠธ๋กœ ๋ฌธ์ž์—ด ํ’€๋ผ๋‹ˆ๊นŒ ๋„ˆ๋ฌด ํž˜๋“ค์–ด -.-

์Šค์œ„ํ”„ํŠธ์—์„œ๋Š” ๋ฌธ์ž์—ด input์„ input[0] ์ด๋Ÿฐ ์‹์œผ๋กœ ์ธ๋ฑ์‹ฑํ•˜๋Š” ๊ฒƒ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.
๋”ฐ๋ผ์„œ ์ฒซ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ ๊ตฌํ•˜๊ธฐ ์œ„ํ•ด input[input.startIndex]๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค.

uppercased()๋กœ ์›๋ณธ ๋ฌธ์ž์—ด์˜ ์ฒซ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊ฟ”์ฃผ๊ณ  upper๋ผ๋Š” ์ƒˆ๋กœ์šด ๋ณ€์ˆ˜์— ๊ฐ’์„ ์ €์žฅํ–ˆ๋‹ค.

removeFirst(1)๋กœ ์›๋ณธ ๋ฌธ์ž์—ด์˜ ์•ž์—์„œ๋ถ€ํ„ฐ 1๊ฐœ์˜ ๋ฌธ์ž, ์ฆ‰ ์ฒซ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ ์‚ญ์ œํ–ˆ๋‹ค. ์ด ๋ฉ”์†Œ๋“œ๋Š” ๋ฐฐ์—ด์— ๋Œ€ํ•ด์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ทธ๋Ÿผ ์ด์ œ upper์™€ ์›๋ณธ ๋ฌธ์ž์—ด์„ ์ด์–ด๋ถ™์—ฌ ์ถœ๋ ฅํ•˜๋ฉด ์ •๋‹ต์ด ๋œ๋‹ค.




๐Ÿ“ง 13163 ๋‹‰๋„ค์ž„์— ๊ฐ“ ๋ถ™์ด๊ธฐ

๐Ÿ“Œ ๋ฌธ์ œ

๋ฐฉ๊ธˆ ๋ง‰ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ๋ฐฐ์šฐ๊ธฐ ์‹œ์ž‘ํ•œ ์ฐฌ์šฐ๋Š” acmicpc.net์— ์žˆ๋Š” ํšŒ์›๋“ค์ด ๋ชจ๋‘ ์‹ ๊ฐ™์ด ๋ณด์˜€๋‹ค. ๊ทธ๋ž˜์„œ ์ฐฌ์šฐ๋Š” ๋ชจ๋“  ํšŒ์›์˜ ๋‹‰๋„ค์ž„ ์•ž์— โ€˜๊ฐ“โ€™์„ ๋ถ™์ด๋ ค๊ณ  ํ•œ๋‹ค.

์ฐฌ์šฐ๊ฐ€ โ€˜koosagaโ€™๋ผ๋Š” ๋‹‰๋„ค์ž„์„ ๊ฐ€์ง„ ํšŒ์›์„ ๊ฐ“์œผ๋กœ ๋ฐ”๊ฟ” ๋ถ€๋ฅธ๋‹ค๋ฉด โ€˜godsagaโ€™๊ฐ€ ๋œ๋‹ค. ๋˜, ์ฐฌ์šฐ๊ฐ€ โ€˜ackaโ€™๋ผ๋Š” ๋‹‰๋„ค์ž„์„ ๊ฐ€์ง„ ํšŒ์›์„ ๊ฐ“์œผ๋กœ ๋ฐ”๊ฟ” ๋ถ€๋ฅธ๋‹ค๋ฉด โ€˜godkaโ€™๊ฐ€ ๋  ๊ฒƒ์ด๋‹ค. ์ฐฌ์šฐ๋Š” ๋‹‰๋„ค์ž„์„ ๊ฐ“์œผ๋กœ ๋ฐ”๊พธ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ƒ๊ฐํ•˜๋‹ค๊ฐ€, ์•„๋ž˜์™€ ๊ฐ™์ด 2๋‹จ๊ณ„ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ๋  ๊ฒƒ์œผ๋กœ ์ƒ๊ฐํ–ˆ๋‹ค.

  • ๋‹‰๋„ค์ž„์„ ์Œ์ ˆ ๋‹จ์œ„๋กœ ์ชผ๊ฐ ๋‹ค.
  • ๊ฐ€์žฅ ์ฒซ ์Œ์ ˆ์„ โ€˜godโ€™์œผ๋กœ ๋ฐ”๊พผ ํ›„ ์ชผ๊ฐ  ์Œ์ ˆ์„ ํ•ฉ์นœ๋‹ค.

์ฐฌ์šฐ๋Š” ์ˆ˜์ž‘์—…์œผ๋กœ N๋ช…์˜ ๋‹‰๋„ค์ž„์„ ๋ชจ๋‘ ์Œ์ ˆ ๋‹จ์œ„๋กœ ์ชผ๊ฐฐ๋‹ค. ์ฐฌ์šฐ๋ฅผ ๋„์™€ ์ด ๋‹‰๋„ค์ž„๋“ค์— ๊ฐ“์„ ๋ถ™์ด๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์ž.

์ž…๋ ฅ

์ฒซ ๋ฒˆ์งธ ์ค„์—๋Š” ๋‹‰๋„ค์ž„์˜ ์ˆ˜ N(1 โ‰ค N โ‰ค 100)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘ ๋ฒˆ์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ์Œ์ ˆ ๋‹จ์œ„๋กœ ์ชผ๊ฐ  ๋‹‰๋„ค์ž„์ด ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ์ค„์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž์™€ ๊ณต๋ฐฑ๋งŒ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋ฉฐ, ์ชผ๊ฐ  ๋‹‰๋„ค์ž„์˜ ์ด ๊ธธ์ด(๊ณต๋ฐฑ ํฌํ•จ)๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. ์ชผ๊ฐ  ๋‹‰๋„ค์ž„์—๋Š” 1๊ฐœ ์ด์ƒ์˜ ๊ณต๋ฐฑ์ด ์กด์žฌํ•œ๋‹ค.

์ถœ๋ ฅ

๊ฐ ์ค„์— ํ•˜๋‚˜์”ฉ ๊ฐ“์„ ๋ถ™์ธ ๋‹‰๋„ค์ž„์„ ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1

5
baek joon
koo sa ga
ac ka
yu ka ri ko
ke sa ki yo

์˜ˆ์ œ ์ถœ๋ ฅ 1

godjoon
godsaga
godka
godkariko
godsakiyo

๐Ÿ“Œ ํ’€์ด

๐Ÿ’ฌ Code

for _ in 0..<Int(String(readLine()!))! {
  let nickname = readLine()!.split(separator: " ")
  print("god\(nickname.dropFirst().joined())")
}

๐Ÿ’ก Comment

์ง์ „ ๋ฌธ์ œ์—์„œ ์‚ฌ์šฉํ–ˆ๋˜ removeFirst๋Š” ๋ฐฐ์—ด์„ ์ˆ˜์ •ํ•˜์ง€๋งŒ, dropFirst๋Š” ๋ฐฐ์—ด์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š๋Š”๋‹ค. ์›๋ณธ ๋ฐฐ์—ด์˜ ์ฒซ๋ฒˆ์งธ ์›์†Œ๊ฐ€ ์‚ญ์ œ๋œ ๋ชจ์–‘์˜ ๋ฐฐ์—ด์„ ๋ฆฌํ„ดํ•œ๋‹ค. ๊ทธ๋ž˜์„œ nickname ๋ฐฐ์—ด์„ let์œผ๋กœ ์„ ์–ธํ•ด๋„ ๋ฌธ์ œ์—†์ด ๋™์ž‘ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

๋ฐฐ์—ด์˜ ๋’ค์— joined๋ฅผ ๋ถ™์ด๋ฉด ๋ฐฐ์—ด์˜ ์›์†Œ๋“ค์„ ๊ฒฐํ•ฉํ•ด ๋ฌธ์ž์—ด๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.




๐Ÿ“ง 3181 ์ค„์ž„๋ง ๋งŒ๋“ค๊ธฐ

๐Ÿ“Œ ๋ฌธ์ œ

๊ฟ์€ ๋งŒ์‚ฌ๊ฐ€ ๊ท€์ฐฎ์•„์„œ ๋ง์„ ํ•˜๊ธฐ๋„ ๊ท€์ฐฎ์•„ ํ•œ๋‹ค. ๊ทธ๋ž˜์„œ ํ•˜๋ ค๋Š” ๋ง์„ ๋Œ€์‹ ํ•ด์ค„ ์ค„์ž„๋ง์„ ๋งŒ๋“ค๋ ค๊ณ  ํ•˜๋Š”๋ฐ ๋‚˜๋ฆ„ ๊ทœ์น™์„ ๋งŒ๋“ค์—ˆ๋‹ค.

ํ•˜๋ ค๋Š” ๋ง์€ ์ตœ์†Œ ํ•˜๋‚˜ ์ด์ƒ์˜ ๋‹จ์–ด๋ฅผ ํฌํ•จํ•˜๋Š”๋ฐ ๊ฐ ๋‹จ์–ด๋“ค์€ ์ •ํ™•ํžˆ ํ•œ์นธ์˜ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„์ด ๋œ๋‹ค. ์ค„์ž„๋ง์„ ๋งŒ๋“ค๋•Œ๋Š” ๊ฐ ๋‹จ์–ด์˜ ์•ž๊ธ€์ž๋ฅผ ๋”ฐ์„œ ๋งŒ๋“ค์–ด์ง€๋Š”๋ฐ ๋‹ค์Œ์˜ ๋‹จ์–ด๋“ค์€ ์“ธ๋ชจ์—†๋Š” ๋‹จ์–ด๋“ค์ด๋ฏ€๋กœ ๋ฌด์‹œํ•œ๋‹ค.

  • 'i', 'pa', 'te', 'ni', 'niti', 'a', 'ali', 'nego', 'no', 'ili'.

ํ•˜์ง€๋งŒ ์ด ๋‹จ์–ด๋“ค์ด ํ•˜๋ ค๋Š” ๋ง์˜ ๋งจ ์•ž์— ์˜ฌ๊ฒฝ์šฐ ๋งค์šฐ ์ค‘์š”ํ•˜๋‹ค๊ณ  ํŒ๋‹จ๋˜์–ด ๋ฌด์‹œํ•˜๋ฉด ์•ˆ๋˜๊ณ  ์ค„์ž„๋ง์— ํฌํ•จํ•˜์—ฌ์•ผ ํ•œ๋‹ค.

์ค„์ž„๋ง์„ ๋งŒ๋“ค๊ธฐ๋„ ๊ท€์ฐฎ์•„์ง„ ๊ฟ์„ ์œ„ํ•ด ์ค„์ž„๋ง์„ ๋งŒ๋“ค์–ด์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ.

๋‹จ, ์ค„์ž„๋ง์€ ๋ชจ๋‘ ๋Œ€๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ์žˆ๋‹ค.

์ž…๋ ฅ

์ž…๋ ฅ์€ ์œ ์ผํ•˜๊ฒŒ ํ•œ ์ค„๋งŒ ์ฃผ์–ด์ง€๋ฉฐ ํ•˜๋ ค๋Š” ๋ง์ด ํฌํ•จ๋˜์–ด ์žˆ๋‹ค.

๋ฌธ์žฅ์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž์™€ ๊ณต๋ฐฑ์œผ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค.

๋ฌธ์žฅ์˜ ์ตœ๋Œ€๊ธธ์ด๋Š” 100์ด๋‹ค.

์ถœ๋ ฅ

๋งŒ๋“ค์–ด์ง„ ์ค„์ž„๋ง์„ ์ถœ๋ ฅํ•˜๋ผ.

์˜ˆ์ œ ์ž…๋ ฅ 1

micro soft

์˜ˆ์ œ ์ถœ๋ ฅ 1

MS

์˜ˆ์ œ ์ž…๋ ฅ 2

biti ali i ne biti

์˜ˆ์ œ ์ถœ๋ ฅ 2

BNB

์˜ˆ์ œ ์ž…๋ ฅ 3

ali ja sam i jucer jeo

์˜ˆ์ œ ์ถœ๋ ฅ 3

AJSJJ

๐Ÿ“Œ ํ’€์ด

๐Ÿ’ฌ Code

var input = readLine()!.split(separator: " ")
let skip = ["i", "pa", "te", "ni", "niti", "a", "ali", "nego", "no", "ili"]
var idx = 0

for str in input {
  if skip.contains(String(str)) && idx > 0 {
    continue
  } else {
    print(str[str.startIndex].uppercased(), terminator: "")
  }
  idx += 1
}
profile
๊ธฐ๋กํ•˜๋Š” ๊ฐœ๋ฐœ์ž ๐Ÿ‘€

0๊ฐœ์˜ ๋Œ“๊ธ€