[프로그래머스] 혼자서 하는 틱택토
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
vector<string> b;
bool getWin(char me){
for(int i = 0; i<3; ++i){
if((b[i][0] == me)&&(b[i][0] == b[i][1])&&(b[i][1] == b[i][2]))
return true;
if((b[0][i] == me)&&(b[0][i] == b[1][i])&&(b[1][i] == b[2][i]))
return true;
}
if((b[0][0] == me)&&(b[0][0] == b[1][1]) && (b[1][1] == b[2][2]))
return true;
if((b[0][2] == me)&&(b[0][2] == b[1][1]) && (b[1][1] == b[2][0]))
return true;
return false;
}
int solution(vector<string> board) {
b = board;
int o_cnt = 0;
int x_cnt = 0;
for(int i = 0; i<3; ++i){
for(int j = 0; j<3; ++j){
if(board[i][j] == 'O') o_cnt++;
else if(board[i][j] == 'X') x_cnt++;
}
}
if(x_cnt > o_cnt) return 0;
if((o_cnt - x_cnt) > 1) return 0;
bool o_win = getWin('O');
bool x_win = getWin('X');
if(o_win && x_win) return 0;
if(o_win && !x_win) return o_cnt > x_cnt;
if(!o_win && x_win) return o_cnt == x_cnt;
return 1;
}