inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

10주완성 C++ 코딩테스트 | 알고리즘 코딩테스트

2-L

안녕하세요 제 코드에 반례가 있을까요?

347

권성민

작성한 질문수 2

0

문제를 풀어서 보여지는 테스트 케이스는 다 맞는데 반례가 있을까요?

#include <bits/stdc++.h>
using namespace std;
int n;
int temp;
pair<int, int> team1;
pair<int, int> team2;
int team1total;
int team2total;
string mmss;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> temp >> mmss;
        string m = mmss.substr(0,2);
        string s = mmss.substr(3,2);
        int mm = atoi(m.c_str());

        int ss = atoi(s.c_str()) + 60*mm;

        if(team1.first == team2.first){
            if(temp == 1){
                team1.first++;
                team1.second = ss;
            }else{
                team2.first++;
                team2.second = ss;
            }
        }else if(team1.first > team2.first){
            if(temp == 1){
                team1.first++;
            }else{
                team2.first++;
                if(team1.first == team2.first){
                    team1total += ss - team1.second;
                    team1.second = 0;
                    team2.second = 0;
                }
            }
        }else if(team1.first < team2.first){
            if(temp == 2){
                team2.first++;
            }else{
                team2.first++;
                if(team1.first == team2.first){
                    team2total += ss - team2.second;
                    team2.second = 0;
                    team1.second = 0;
                }
            }
        }
    }

    if(team1.second != 0){
       team1total += 48*60 - team1.second;
    }else if(team2.second != 0){
        team2total += 48*60 - team2.second;
    }

    string total1Time_first = to_string(team1total / 60);
    string total1Time_second = to_string(team1total % 60);
    string total2Time_first = to_string(team2total / 60);
    string total2Time_second = to_string(team2total % 60);

    if(total1Time_first.length() == 1)total1Time_first = "0" + total1Time_first;
    if(total1Time_second.length() == 1)total1Time_second = total1Time_second +"0";
    if(total2Time_first.length() == 1)total2Time_first = "0" + total1Time_first;
    if(total2Time_second.length() == 1)total2Time_second = total2Time_second +"0";


    cout << total1Time_first+":"+total1Time_second << "\n";
    cout << total2Time_first+":"+total2Time_second << "\n";
    return 0;
}

c++ 코딩-테스트

답변 1

0

큰돌

안녕하세요 성민님 ㅎㅎ

예제 5를 입력하게 되면 다음과 같이 뜹니다. 제대로 동작하지 않습니다.

해당 부분이 반례인 것 같습니다 확인 부탁드립니다.

5
1 01:10
1 02:20
2 45:30
2 46:40
2 47:50
45:30
045:10

 

또 질문 있으시면 언제든지 질문 부탁드립니다.

좋은 수강평과 별점 5점은 제가 큰 힘이 됩니다. :)

감사합니다.

강사 큰돌 올림.

0

권성민

감사합니다

코딩살구클럽 가입 문의

0

27

2

코딩 살구 클럽 컴파일 에러

0

19

1

추천 문제

0

18

1

코딩살구클럽 승인

0

25

1

코살구 1주차 1940번 문제 조건과 프라이빗 테스트 불일치 문의

0

34

2

문제를 고민하는 시간 관련

0

27

2

코딩살구클럽

0

42

2

코딩살구클럽 문의

0

45

2

코딩살구클럽 승인

0

37

2

DP 경우의 수 설명이 이해가 되지 않습니다.

0

35

2

3-F 채점 관련 질문

0

32

1

BFS, DFS 활용이 되는 상황에서의 방향성

0

34

2

코딩살구클럽 승인

0

46

2

코딩살구클럽승인

0

39

3

코딩살구클럽 승인

0

56

2

3-D 관련 질문

0

35

2

코살구 회원가입 문의

0

45

2

코살구 로그인 문제

0

65

2

3-A 문제 풀이 관련 질문

0

56

3

2-O 질문 있습니다

0

38

2

2-T 문제에 관한 질문

0

40

2

코딩 살구 클럽 접속 및 사용방법 문의

0

66

2

안녕하세요~. 현재 코살코딩클럽 사이트가 접속이 안됩니다~

0

67

2

코딩살구클럽 로그인문제

0

85

3