https://www.spoj.pl/problems/TOE1/ For which test case does this program fail????
#include<iostream> #include<vector> using namespace std; bool isWin(vector< vector<char> > &v, char ch); int main() { vector<char> col(3); vector< vector<char> > v(3, col); int t, i, j; bool x, o; cin >> t; while(t--) { int counto = 0, countx = 0; for(i=0; i<3; i++) for(j=0; j<3; j++) { cin >> v[i][j]; if(v[i][j] == 'O') counto++; else if(v[i][j] == 'X') countx++; } //cout << countx << " " << counto << endl; if(! ( (countx == counto + 1) || (countx == counto) ) ) cout << "no" << endl; else { x = isWin(v, 'X'); o = isWin(v, 'O'); //cout << "x = " << x << " o = " << o<< endl; if(o && x) cout << "no" << endl; else cout << "yes" << endl; } } return 0; } bool isWin(vector< vector<char> > &v, char ch) { int i, j=0; for(i=0; i<3; i++) { if(v[i][j] == v[i][j+1] && v[i][j+1] == v[i][j+2] && v[i] [j] == ch) return true; } i=0; for(j=0; j<3; j++) { if(v[i][j] == v[i+1][j] && v[i+1][j] == v[i+2][j] && v[i] [j] == ch) return true; } if(v[0][0] == v[1][1] && v[1][1] == v[2][2] && v[0][0] == ch) return true; if(v[2][0] == v[1][1] && v[1][1] == v[0][2] && v[1][1] == ch) return true; return false; } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.