#include "bits/stdc++.h"
using namespace std;
int s1 = 0;
int s2 = 0;
int t1 = 0;
int t2 = 0;
int lasttime = 0;
string o;
int GetTimeInt(string input)
{
string hour = input.substr(0, 2);
string minute = input.substr(3, 2);
int time = stoi(hour) * 60 + stoi(minute);
return time;
}
string GetTimeString(int time)
{
int hour = time / 60;
int minute = time - hour * 60;
string final = "";
std::stringstream ss;
std::stringstream ss2;
ss << std::setw(2) << std::setfill('0') << hour;
final += ss.str() + ":";
ss2 << std::setw(2) << std::setfill('0') << minute;
final += ss2.str();
return final;
}
void AddScore(int team)
{
if (team == 1)
s1++;
if (team == 2)
s2++;
}
int WhoWin()
{
if (s1 > s2) return 1;
if (s1 < s2) return 2;
if (s1 == s2) return 0;
}
int main() {
int goal;
cin >> goal;
string data;
int currentLeader = 0; // 현재 리드하는 팀 (0=무승부)
for (int a = 0; a < goal; a++)
{
cin >> o >> data;
int scoreTeam = o[0] - '0';
int currentTime = GetTimeInt(data);
if (currentLeader == 1)
t1 += currentTime - lasttime;
else if (currentLeader == 2)
t2 += currentTime - lasttime;
// 점수 업데이트
AddScore(scoreTeam);
currentLeader = WhoWin();
// 현재 시간 저장
lasttime = currentTime;
}
int endTime = 48 * 60; // 경기가 48분에 끝난다고 가정
if (currentLeader == 1)
t1 += endTime - lasttime;
else if (currentLeader == 2)
t2 += endTime - lasttime;
std::cout << GetTimeString(t1) << endl;
std::cout << GetTimeString(t2);
}
시간안에 풀지 못했던 문제
substr 매개변수의 의미를 제대로 파악하지 못하고 있었고
그리고 cin으로 받을 때 중간에 공백이 있으면 받는 스킬을 제대로 알지 못하였다.
이전 값을 저장하는 부분등 전체적인 구현능력과 사고능력이 부족했다.
또한 포멧 만드는 능력도 부족하였다.
지금setw를 이용해서 포멧을 만들어주고 있는데 "00"을 더해준뒤 substr을 이용해 하는 편이 좀더 직관적일 것 같다.
다시 한번 풀어봐야 하는 문제
'코딩테스트' 카테고리의 다른 글
[백준] 9012 괄호 (0) | 2025.05.30 |
---|---|
[백준] 1436 영화감독 숌 (0) | 2025.05.30 |
[백준] 3474번 교수가 된 현우 (2) | 2025.04.30 |
[백준] 10709번 기상캐스터 (0) | 2025.04.30 |
[백준] 2870번 수학숙제 (0) | 2025.04.30 |