알고리즘/BOJ

백준 14654번 스테판 쿼리

꾸준함. 2018. 8. 9. 01:41

문제 링크입니다: https://www.acmicpc.net/problem/14654


단순 구현 문제였습니다.

문제에서 요구하는대로만 구현을 한다면 AC를 받을 수 있는 문제였기 때문에 설명은 생략하겠습니다.


#include <iostream>

#include <algorithm>

using namespace std;

 

const int MAX = 300;

 

int N;

pair<int, int> arr[MAX];

 

int maxStraightWins(void)

{

        int team1 = 0, team2 = 0;

        int result = 0;

 

        for (int i = 0; i < N; i++)

        {

                 //비긴 경우 새로 출전한 사람이 승을 챙김

                 if (arr[i].first == arr[i].second)

                 {

                         if (!team1)

                         {

                                 team1++;

                                 result = max(result, team2);

                                 team2 = 0;

                         }

                         else

                         {

                                 team2++;

                                 result = max(result, team1);

                                 team1 = 0;

                         }

                         continue;

                 }

 

                 //승패를 가른다

                 switch (arr[i].first)

                 {

                 case 1:

                         switch (arr[i].second)

                         {

                         case 2:

                                 team2++;

                                 result = max(result, team1);

                                 team1 = 0;

                                 break;

                         case 3:

                                 team1++;

                                 result = max(result, team2);

                                 team2 = 0;

                                 break;

                         }

                         break;

                 case 2:

                         switch (arr[i].second)

                         {

                         case 1:

                                 team1++;

                                 result = max(result, team2);

                                 team2 = 0;

                                 break;

                         case 3:

                                 team2++;

                                 result = max(result, team1);

                                 team1 = 0;

                                 break;

                         }

                         break;

                 case 3:

                         switch (arr[i].second)

                         {

                         case 1:

                                 team2++;

                                 result = max(result, team1);

                                 team1 = 0;

                                 break;

                         case 2:

                                 team1++;

                                 result = max(result, team2);

                                 team2 = 0;

                                 break;

                         }

                         break;

                 }

        }

       

        return max({ result, team1, team2 });

}

 

int main(void)

{

        ios_base::sync_with_stdio(0);

        cin.tie(0);

        cin >> N;

 

        for (int i = 0; i < N; i++)

                 cin >> arr[i].first;

        for (int i = 0; i < N; i++)

                 cin >> arr[i].second;

 

        cout << maxStraightWins() << "\n";

        return 0;

}


개발환경:Visual Studio 2017


지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형