inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

2-L

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

355

권성민

작성한 질문수 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

권성민

감사합니다

6-H 체점 관련 질문

0

8

0

채점서버 연결 관련 질문입니다

0

31

1

삼성 s직군

0

33

0

삼성 코테 없어짐

0

81

1

코딩살구클럽 가입부탁드립니다

0

40

2

코딩살구클럽 가입 요청 확인부탁드립니다

0

35

2

5-S 테스트 케이스 질문

0

37

2

코살 문제풀이 환경

0

54

2

2 - T 오큰수 문제가 있는 것 같습니다.

0

46

1

추천 추가문제들

0

44

2

프로그래머스 코테 환경 관련해서 질문드립니다.

0

50

2

해당 문제에 대한 채점이 코딩살구클럽에서 올바르게 처리되지 않습니다.

0

44

2

균형 이진 트리 설명 시 높이 숫자

0

33

2

4-H 질문드립니다.

0

37

2

1-K 질문드립니다.

0

43

2

대기업 인적성 시험 질문

0

43

2

4-C 질문드립니다

0

43

2

[수학숙제 / BOJ 2870] 채점 서버 오작동

0

40

1

코테 준비 질문

0

58

1

살구클럽가입 요청드려요

0

42

2

1-I 문제 질문

0

46

2

코딩살구클럽 가입

0

61

2

AI 코딩 도구 사용 시 학습 방법 조언

0

56

2

코딩살구클럽 오류

0

67

2