본문 바로가기
SWEA

[SWEA] 11545 틱택톰

by 콩순이냉장고 2021. 5. 25.

문제URL : https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=4&problemLevel=5&contestProbId=AXeJGPgqR9cDFAS5&categoryId=AXeJGPgqR9cDFAS5&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=5&pageSize=10&pageIndex=1 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

문제 접근법 : 가로선 ,세로선 ,대각선 중에 O가 4개인지 X가 4개인지만 카운트해서 찾는문제입니다.

단 T가 있을때 O의개수 + T의개수를 세서 4개가 나오면 걔가 정답이겠죠 그치만 조건에 T의 개수가 3+1개일때 라는 조건이 나와있는데 처음 제출했을때 t의개수  체크안했는데도 답이 맞았어요

좋은 테스트케이스가 없는듯합니다. 물론 답을 제대로된 답을 체크해서 고쳐야겠지요?? 

 

 

소스코드 : 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//By콩순이냉장고
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
char board[4][4];
int shape[300= { 0 };
int cnt = 0;
string s[4= { "Game has not completed" ,"X won","O won" ,"Draw" };
void input() {
    cnt = 0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            cin >> board[i][j];
            if (board[i][j] == '.')
                cnt++;
        }
    }
}
 
int check(int *count) {
    if (count[1+ count[3== 4&&count[3]<=1)//T가 1개이하여야함
        return 1;
    if (count[2+ count[3== 4&&count[3]<=1)
        return 2;
    return 0;
}
 
void solve() {
    
    int flag = 0;
 
    shape['X'= 1;
    shape['O'= 2;
    shape['T'= 3;
    for (int i = 0; i < 4; i++) {
        int count[4= { 0 };
        for (int j = 0; j < 4; j++) {
            count[shape[board[i][j]]]++;
        }
        flag = check(count);
        if (flag) {
            cout << s[flag] << "\n";
            return;
        }
    }
    for (int j = 0; j < 4; j++) {
        int count[4= { 0 };
        for (int i = 0; i < 4; i++) {
            count[shape[board[i][j]]]++;
        }
        flag = check(count);
        if (flag) {
            cout << s[flag] << "\n";
            return;
        }
    }
    int count[2][4= { 0 };
    for (int i = 0; i < 4; i++) {
        count[0][shape[board[i][i]]]++;
        count[1][shape[board[i][3 - i]]]++;
    }
 
    flag = check(count[0]);
    if (flag) {
        cout << s[flag] << "\n";
        return;
    }
    flag = check(count[1]);
    if (flag) {
        cout << s[flag] << "\n";
        return;
    }
 
    if (cnt == 0)
        cout << s[3<< "\n";
    else
        cout << s[0<< "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int test;
    cin >> test;
    for(int i=1;i<=test;i++){
        input();
        cout << "#" << i << " ";
        solve();
    }
}
cs

 

궁금한점 혹은 어떤질문이든 댓글은 환영입니다.