문제 링크입니다: www.acmicpc.net/problem/5575
5575번: 타임 카드
JOI 상사는 직원의 근무시간을 타임 카드로 관리하고있다. 직원들은 전용 장비를 사용하여 타임 카드에 출근 시간을 기록한다. 근무를 마치고 퇴근할 때도 타임 카드에 퇴근 시간을 기록한다.
www.acmicpc.net
초와 분의 범위가 0 ~ 59 사이라는 것을 명심합시다!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
const int MAX = 3; | |
const int MAX_SECOND = 60; | |
const int MAX_MINUTE = 60; | |
typedef struct | |
{ | |
int startTime[MAX]; | |
int endTime[MAX]; | |
} Employee; | |
void printDiff(Employee employee) | |
{ | |
int hour = employee.endTime[0] - employee.startTime[0]; | |
int minute = employee.endTime[1] - employee.startTime[1]; | |
int second = employee.endTime[2] - employee.startTime[2]; | |
if (second < 0) | |
{ | |
second += MAX_SECOND; | |
minute--; | |
} | |
if (minute < 0) | |
{ | |
minute += MAX_MINUTE; | |
hour--; | |
} | |
cout << hour << " " << minute << " " << second << "\n"; | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
for (int employeeIdx = 0; employeeIdx < MAX; employeeIdx++) | |
{ | |
Employee employee; | |
for (int startIdx = 0; startIdx < MAX; startIdx++) | |
{ | |
cin >> employee.startTime[startIdx]; | |
} | |
for (int endIdx = 0; endIdx < MAX; endIdx++) | |
{ | |
cin >> employee.endTime[endIdx]; | |
} | |
printDiff(employee); | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 5596번 시험 점수 (0) | 2021.03.11 |
---|---|
백준 5543번 상근날드 (0) | 2021.03.11 |
백준 4299번 AFC 윔블던 (2) | 2021.03.09 |
백준 3004번 체스판 조각 (3) | 2021.03.09 |
백준 1297번 TV 크기 (0) | 2021.03.07 |