井字棋
如何写一个函数,判断井字棋的胜利 #include <bits/stdc++.h>using namespace std;
char mp;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
for(int i = 1; i <= 3; i++){
for(int j = 1; j <= 3; j++){
cin >> mp;
}
}
for(int i = 1; i <= 3; i++){// 行和列判断是否有连续的
if(mp == mp && mp == mp){
cout << mp << " wins";
return 0;
}
if(mp == mp && mp == mp){
cout << mp << " wins";
return 0;
}
}
// 两个对角线判断是否连
if(mp == mp && mp == mp){
cout << mp << " wins";
return 0;
}
if(mp == mp && mp == mp){
cout << mp << " wins";
return 0;
}
cout << "Nobody wins";
return 0;
}
页:
[1]