[백준 28097] 모범생 포닉스 (C#, C++) - soo:bak
작성일 :
문제 링크
설명
n개의 공부 계획을 순서대로 수행하며, 각 계획 사이에 8시간씩 휴식할 때 총 소요 시간을 구하는 문제입니다.
마지막 계획 뒤에는 휴식이 없으며, 결과를 일과 시간으로 출력합니다.
접근법
모든 계획 시간을 합산하고, 휴식 시간 8 × (n - 1)을 더합니다.
총 시간을 24로 나눈 몫이 일, 나머지가 시간입니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine()!);
var arr = Array.ConvertAll(Console.ReadLine()!.Split(), int.Parse);
var total = 0;
for (var i = 0; i < n; i++) {
total += arr[i];
if (i != n - 1) total += 8;
}
Console.WriteLine($"{total / 24} {total % 24}");
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
int total = 0;
for (int i = 0; i < n; i++) {
int t; cin >> t;
total += t;
if (i != n - 1) total += 8;
}
cout << total / 24 << " " << total % 24 << "\n";
return 0;
}