ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

Algorithm

[Algorithm] 10250 ACM ํ˜ธํ…”

_๋ณด๋ฆ„ 2021. 4. 21. 17:06

๐Ÿ–ฅ ๋ฌธ์ œ

ACM ํ˜ธํ…” ๋งค๋‹ˆ์ € ์ง€์šฐ๋Š” ์†๋‹˜์ด ๋„์ฐฉํ•˜๋Š” ๋Œ€๋กœ ๋นˆ ๋ฐฉ์„ ๋ฐฐ์ •ํ•˜๊ณ  ์žˆ๋‹ค. ๊ณ ๊ฐ ์„ค๋ฌธ์กฐ์‚ฌ์— ๋”ฐ๋ฅด๋ฉด ์†๋‹˜๋“ค์€ ํ˜ธํ…” ์ •๋ฌธ์œผ๋กœ๋ถ€ํ„ฐ ๊ฑธ์–ด์„œ ๊ฐ€์žฅ ์งง์€ ๊ฑฐ๋ฆฌ์— ์žˆ๋Š” ๋ฐฉ์„ ์„ ํ˜ธํ•œ๋‹ค๊ณ  ํ•œ๋‹ค. ์—ฌ๋Ÿฌ๋ถ„์€ ์ง€์šฐ๋ฅผ ๋„์™€ ์ค„ ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๊ณ ์ž ํ•œ๋‹ค. ์ฆ‰ ์„ค๋ฌธ์กฐ์‚ฌ ๊ฒฐ๊ณผ ๋Œ€๋กœ ํ˜ธํ…” ์ •๋ฌธ์œผ๋กœ๋ถ€ํ„ฐ ๊ฑท๋Š” ๊ฑฐ๋ฆฌ๊ฐ€ ๊ฐ€์žฅ ์งง๋„๋ก ๋ฐฉ์„ ๋ฐฐ์ •ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๊ณ ์ž ํ•œ๋‹ค.

๐Ÿค” ํ’€์ด ๋ฐฉ๋ฒ•

  1. ๋ณ€์ˆ˜
    • floor: Int : ๋ฐฐ์ •๋œ ์ธต
    • room: String : ๋ฐฐ์ •๋œ ๋ฒˆํ˜ธ๋ฅผ ์ŠคํŠธ๋ง ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•œ ๊ฐ’. 1ํ˜ธ์˜ ๊ฒฝ์šฐ 01ํ˜ธ๋กœ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•จ
    • tmpRoom: Int : ๋ฐฐ์ •๋œ ๋ฒˆํ˜ธ
  2. floor = N % H
    • N์„ H๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๊ฐ€ ๋ฐฐ์ •๋œ ์ธต์ด ๋œ๋‹ค.
    • 5์ธต ๊ฑด๋ฌผ์— 7๋ฒˆ์งธ ์‚ฌ๋žŒ -> 2์ธต
  3. tmpRoom = N / H
    • N์„ H๋กœ ๋‚˜๋ˆˆ ๋ชซ์ด ๋ฐฐ์ •๋œ ๋ฒˆํ˜ธ๊ฐ€ ๋œ๋‹ค.
    • 5์ธต ๊ฑด๋ฌผ์— 7๋ฒˆ์งธ ์‚ฌ๋žŒ -> 2๋ฒˆ
  4. if floor == 0 { floor = H } else { tmpRoom += 1 }
    • floor๊ฐ€ 0์ผ ๊ฒฝ์šฐ ๊ฑด๋ฌผ์˜ ์ตœ์ƒ์ธต์ด๋‹ค.
    • 5์ธต ๊ฑด๋ฌผ์— 10๋ฒˆ์งธ ์‚ฌ๋žŒ์ผ ๊ฒฝ์šฐ floor๋Š” 0์ด๋‹ค. -> ์ด๊ฒฝ์šฐ ์ตœ์ƒ์ธต์ธ 5์ธต์œผ๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค.
    • 0์ด ์•„๋‹ ๊ฒฝ์šฐ ๋ฒˆํ˜ธ๋ฅผ 1 ์ฆ๊ฐ€์‹œ์ผœ์ค€๋‹ค.
    • 5์ธต ๊ฑด๋ฌผ์— 10๋ฒˆ์งธ ์‚ฌ๋žŒ -> 2ํ˜ธ
    • 5์ธต ๊ฑด๋ฌผ์— 9๋ฒˆ์งธ ์‚ฌ๋žŒ -> 1ํ˜ธ -> 2ํ˜ธ๋กœ ๋ฐ”๊พธ์–ด์ค€๋‹ค.
  5. if tmpRoom == tmpRoom % 10 { room = "0\(tmpRoom)" } else { room = "\(tmpRoom)" }
    • ๋ฐฐ์ •๋œ ๋ฒˆํ˜ธ๊ฐ€ 5ํ˜ธ์™€ ๊ฐ™์ด 1์ž๋ฆฌ ์ˆ˜๋ผ๋ฉด "05ํ˜ธ๋กœ ๋ฐ”๊พธ์–ด์ค€๋‹ค.

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป Swift Code

import Foundation

let T = Int(readLine() ?? "") ?? 0

if 0 < T {
    for _ in 0..<T {
        let line = (readLine() ?? "").split(separator: " ").map{Int(String($0)) ?? 0}
        let H = line[0]
        let W = line[1]
        let N = line[2]

        if 1 <= H && W <= 99 && 1 <= N && N <= H * W {
            var floor = N % H
            var room = ""
            var tmpRoom = N / H

            if floor == 0 {
                floor = H
            } else {
                tmpRoom += 1
            }

            if tmpRoom == tmpRoom % 10 {
                room = "0\(tmpRoom)"
            } else {
                room = "\(tmpRoom)"
            }
            print("\(floor)\(room)")
        }
    }
}

 

 

10250๋ฒˆ: ACM ํ˜ธํ…”

ํ”„๋กœ๊ทธ๋žจ์€ ํ‘œ์ค€ ์ž…๋ ฅ์—์„œ ์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›๋Š”๋‹ค. ํ”„๋กœ๊ทธ๋žจ์˜ ์ž…๋ ฅ์€ T ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋Š”๋ฐ T ๋Š” ์ž…๋ ฅ์˜ ๋งจ ์ฒซ ์ค„์— ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋Š” ํ•œ ํ–‰์œผ๋กœ์„œ H, W, N, ์„ธ ์ •์ˆ˜

www.acmicpc.net

 

๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
๊ธ€ ๋ณด๊ด€ํ•จ