작성일 :

문제 링크

24083번 - 短針 (Hour Hand)

설명

시침이 현재 위치에서 주어진 시간 후 가리키는 눈금을 구하는 문제입니다.


접근법

시침은 1시간에 한 칸씩 이동하고, 12칸 이후 다시 1로 돌아갑니다.

현재 위치에 경과 시간을 더한 뒤 12로 나눈 나머지를 구합니다.

나머지가 0이면 12에 해당합니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
11
using System;

class Program {
  static void Main() {
    var a = int.Parse(Console.ReadLine()!);
    var b = int.Parse(Console.ReadLine()!);
    var pos = (a + b) % 12;
    if (pos == 0) pos = 12;
    Console.WriteLine(pos);
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, b;
  if (!(cin >> a >> b)) return 0;
  int pos = (a + b) % 12;
  if (pos == 0) pos = 12;
  cout << pos << "\n";

  return 0;
}