Skip to content

Commit 54f4acc

Browse files
committed
feat: 1408번 문제 해결
1 parent b277eb0 commit 54f4acc

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

src/problem_includes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "problems/problem_1001.h"
99
#include "problems/problem_10950.h"
1010
#include "problems/problem_10952.h"
11+
#include "problems/problem_1408.h"
1112
#include "problems/problem_1977.h"
1213
#include "problems/problem_2438.h"
1314
#include "problems/problem_2439.h"

src/problem_manager.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ProblemManager::ProblemManager() {
77
// 문제 등록
88
problems_[1000] = solve_problem_1000;
99
problems_[1001] = solve_problem_1001;
10+
problems_[1408] = solve_problem_1408;
1011
problems_[1977] = solve_problem_1977;
1112
problems_[2438] = solve_problem_2438;
1213
problems_[2439] = solve_problem_2439;

src/problems/problem_1408.cc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include "problem_1408.h"
2+
#include <iostream>
3+
#include <iomanip>
4+
#include <sstream>
5+
6+
CTU::CTU() : hour(0), minute(0), second(0) {}
7+
8+
void CTU::input_time() {
9+
std::string t;
10+
std::cin >> t;
11+
hour = (t[0] - '0') * 10 + (t[1] - '0');
12+
minute = (t[3] - '0') * 10 + (t[4] - '0');
13+
second = (t[6] - '0') * 10 + (t[7] - '0');
14+
}
15+
16+
int CTU::get_hour() const { return hour; }
17+
int CTU::get_minute() const { return minute; }
18+
int CTU::get_second() const { return second; }
19+
20+
std::string CTU::str() const {
21+
std::ostringstream oss;
22+
oss << std::setfill('0')
23+
<< std::setw(2) << hour << ":"
24+
<< std::setw(2) << minute << ":"
25+
<< std::setw(2) << second;
26+
return oss.str();
27+
}
28+
29+
void normalize_time(int &hour, int &minute, int &second) {
30+
if (second < 0) {
31+
second += 60;
32+
minute -= 1;
33+
}
34+
if (minute < 0) {
35+
minute += 60;
36+
hour -= 1;
37+
}
38+
if (hour < 0) {
39+
hour += 24;
40+
}
41+
}
42+
43+
void solve_problem_1408() {
44+
std::cout << "=== 1408번 24 문제 해결 ===" << std::endl;
45+
46+
std::cout << "시간을 입력하세요 (예: 13:52:30 14:00:00) : ";
47+
CTU user1, user2;
48+
user1.input_time();
49+
user2.input_time();
50+
std::cout << "입력 : 시간1 = " << user1.str()
51+
<< ", 시간2 = " << user2.str() << "\n";
52+
53+
int h = user2.get_hour() - user1.get_hour();
54+
int m = user2.get_minute() - user1.get_minute();
55+
int s = user2.get_second() - user1.get_second();
56+
57+
normalize_time(h, m, s);
58+
59+
std::cout << "출력 : ";
60+
std::cout << std::setfill('0')
61+
<< std::setw(2) << h << ":"
62+
<< std::setw(2) << m << ":"
63+
<< std::setw(2) << s << std::endl;
64+
65+
std::cout << "================================" << std::endl;
66+
}

src/problems/problem_1408.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef PROBLEM_1408_H
2+
#define PROBLEM_1408_H
3+
4+
#include <string>
5+
6+
class CTU {
7+
private:
8+
int hour;
9+
int minute;
10+
int second;
11+
12+
public:
13+
CTU();
14+
void input_time();
15+
int get_hour() const;
16+
int get_minute() const;
17+
int get_second() const;
18+
std::string str() const;
19+
};
20+
21+
void normalize_time(int &hour, int &minute, int &second);
22+
void solve_problem_1408();
23+
24+
#endif

0 commit comments

Comments
 (0)