|
|
вернуться в форумMay be anyone will tell me what's wrong with this? I read all the topics in the forum, but it doesn't seem serious to me the tests to be wrong - I thing, the problem is in me...So here is my program - if anyone has a little time, could have a look at it - Wrong answer on test2.... #include <iostream.h> #include <stdio.h> int a[8][8],i,j; int wins1(char x,char y, int id) { if ((x <= 'a') || (x >= 'h') || (y <= '1') || (y >= '8')) return 0; if (a[x-'a'-1][y-'1'-1]+a[x-'a'+1][y-'1'+1]==2*(1-id)+1) return 1; if (a[x-'a'-1][y-'1'+1]+a[x-'a'+1][y-'1'-1]==2*(1-id)+1) return 1; return 0; } int wins(char x,char y, int id) { if (x < 'a' || x > 'h' || y < '1' || y > '8') return 0; if ((x >= 'c') && (y >= '3') && (a[x-'a'-1][y-'1'-1]==2*(1-id)+1) && (a[x-'a'-2][y-'1'-2]==0)) return 1; if ((x >= 'c') && (y <= '6') && (a[x-'a'-1][y-'1'+1]==2*(1-id)+1) && (a[x-'a'-2][y-'1'+2]==0)) return 1; if ((x <= 'f') && (y >= '3') && (a[x-'a'+1][y-'1'-1]==2*(1-id)+1) && (a[x-'a'+2][y-'1'-2]==0)) return 1; if ((x <= 'f') && (y <= '6') && (a[x-'a'+1][y-'1'+1]==2*(1-id)+1) && (a[x-'a'+2][y-'1'+2]==0)) return 1; return 0; } int main() { char s[222], p[222]; p[0] = 'a'-1; p[1] = '1'-1; for(i = 0; i < 8; i++) for (j = 0; j < 8; j++) a[i][j] = 0; for (i = 0; i < 32; i++) { gets(s); if (s[0] >='A' && s[0] <= 'Z') s[0] = s[0]-'A'+'a'; a[s[0]-'a'][s[1]-'1'] = 2*(i%2)+1; if (wins(p[0],p[1],1-(i%2)) == 1) { cout<<i+1<<endl; return 0; } if (wins1(s[0],s[1],(i%2)) == 1) { cout<<i+1<<endl; return 0; } p[0] = s[0]; p[1] = s[1]; p[2] = s[2]; } cout << "Draw" << endl; return 0; } |
|
|