[백준] 2852번 : NBA 농구 - C

강재원·2022년 11월 2일
0

[코딩테스트] C/C++

목록 보기
166/200
post-custom-banner



https://www.acmicpc.net/problem/2852

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main() {
    int n;
    scanf("%d",&n);
    int score1=0;
    int score2=0;
    int m1=0;
    int s1=0;
    int m2=0;
    int s2=0;
    int sum1m=0;
    int sum1s=0;
    int sum2m=0;
    int sum2s=0;
    
    for(int i=0;i<n;i++){
        int a;
        char st[6];
        scanf("%d %s",&a,&st);
        
        char *temp = strtok(st,":");
        int k=0;
        int m=0;
        int s=0;
        
        while(temp != NULL){
            char *arr[100];
            arr[k]=temp;
            
            if(k==0){
                m=atoi(arr[k]);
            }
            else if(k==1){
                s=atoi(arr[k]);
            }
            k++;
            
            temp = strtok(NULL, ":");
        }
        
        if(a==1){
            if(score1==score2){
                m1=m;
                s1=s;
            }
            score1++;
            if(score1==score2){
                if(s>=s2){
                    sum2m+=m-m2;
                    sum2s+=s-s2;
                }
                else{
                    sum2m+=m-m2-1;
                    sum2s+=s-s2+60;
                }
            }
        }
        else {
            if(score1==score2){
                m2=m;
                s2=s;
            }
            score2++;
            if(score1==score2){
                if(s>=s1){
                    sum1m+=m-m1;
                    sum1s+=s-s1;
                }
                else{
                    sum1m+=m-m1-1;
                    sum1s+=s-s1+60;
                }
            }
        }
    }
    sum1m += sum1s/60;
    sum1s = sum1s%60;
    sum2m += sum2s/60;
    sum2s = sum2s%60;
          
    if(score1>score2){
        sum1m+=47-m1;
        sum1s+=60-s1;
    }
    else if(score2>score1){
        sum2m+=47-m2;
        sum2s+=60-s2;
    }
          
    sum1m += sum1s/60;
    sum1s = sum1s%60;
    sum2m += sum2s/60;
    sum2s = sum2s%60;
    
    printf("%02d:%02d\n",sum1m,sum1s);
    printf("%02d:%02d\n",sum2m,sum2s);
}
profile
개념정리 & 문법 정리 & 알고리즘 공부
post-custom-banner

0개의 댓글