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

강재원·2022년 11월 2일
0

[코딩테스트] C#

목록 보기
167/200



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

using System;

class Program
{
    static void Main() {
        string st=Console.ReadLine();
        int n=int.Parse(st);
        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++){
            string[] st1=Console.ReadLine().Split(' ');
            int k=int.Parse(st1[0]);
            int m=int.Parse(st1[1].Substring(0,2));
            int s=int.Parse(st1[1].Substring(3));
            
            if(k==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;
          
        Console.WriteLine("{0:D2}:{1:D2}",sum1m,sum1s);
        Console.WriteLine("{0:D2}:{1:D2}",sum2m,sum2s);
        
    }
}
profile
개념정리 & 문법 정리 & 알고리즘 공부

0개의 댓글