https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWrDLM0aRA8DFARG
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
간단한 구현문제.
#include <iostream>
#include <string>
using namespace std;
int strToSec(string &s) {
int hour = stoi(s.substr(0, 2));
int min = stoi(s.substr(3, 2));
int sec = stoi(s.substr(6, 2));
return hour * 60 * 60 + min * 60 + sec;
}
string secToStr(int &n) {
string result;
int sec = n % 60;
result = to_string(sec);
if (sec < 10) result = "0" + result;
result = ":" + result;
n /= 60;
int min = n % 60;
result = to_string(min) + result;
if (min < 10) result = "0" + result;
result = ":" + result;
n /= 60;
int hour = n % 60;
result = to_string(hour) + result;
if (hour < 10) result = "0" + result;
return result;
}
int main() {
int T;
cin >> T;
for (int tc = 1; tc <= T; tc++) {
string now, next;
cin >> now >> next;
int nowSec = strToSec(now);
int nextSec = strToSec(next);
int timeLeft = nextSec - nowSec;
if (timeLeft < 0) timeLeft += 24 * 60 * 60;
cout << "#" << tc << " " << secToStr(timeLeft) << endl;
}
return 0;
}
'코딩 > SWEA' 카테고리의 다른 글
[SWEA] 2477. [모의 SW 역량테스트] 차량 정비소 C++ (0) | 2024.10.10 |
---|---|
[SWEA] 1824. 혁진이의 프로그램 검증 C++ (1) | 2024.10.09 |
[SWEA] 1486. 장훈이의 높은 선반 C++ (1) | 2024.10.09 |
[SWEA] D3. 10912. 외로운 문자 C++ (0) | 2024.09.01 |