一道简单的模板题,检查每个玩家,判断它的对角线,行,列是否都是玩家的字符。我们可以把这个功能写成函数,代码如下:
#include <iostream>
using namespace std;
char cb[4][4];
bool check(char c){
for(int i = 1;i <= 3;i++){
if(cb[i][1] == c && cb[i][2] == c && cb[i][3] == c){
return true;
}
if(cb[1][i] == c && cb[2][i] == c && cb[3][i] == c){
return true;
}
}
if(cb[1][1] == c && cb[2][2] == c && cb[3][3] == c){
return true;
}
if(cb[1][3] == c && cb[2][2] == c && cb[3][1] == c){
return true;
}
return false;
}
int main(){
int t;
cin >> t;
while(t--){
for(int i = 1;i <= 3;i++){
for(int j = 1;j <= 3;j++){
cin >> cb[i][j];
}
}
if(check('C')){
cout << "C";
} else if(check('T')){
cout << "T";
} else if(check('Z')){
cout << "Z";
} else{
cout << "ongoing";
}
cout << '\n';
}
return 0;
}