1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #include <bits/stdc++.h>
#define N 16 #define mod 1000000007 #define FOR(i,n) for(int i=0;i<n;i++) #define ios ios::sync_with_stdio(0) using namespace std; int t;
void solve(){ int maze[10][10],cur[10][10],n; for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ cin>>maze[i][j]; cur[i][j] = maze[i][j]; } } while(cin>>n && n!= -1){ for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ if(maze[i][j]==n)maze[i][j] = 0; } } } int ind = 1,num = -1; for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ if(maze[i][j]!=0){ maze[i][j] = 0; int k,ans = 0; for(k=0;k<5;k++)if(maze[k][j]!=0)break; if(k==5)ans+=1; for(k=0;k<5;k++)if(maze[i][k]!=0)break; if(k==5)ans+=1; if(i==j){ for(k=0;k<5;k++)if(maze[k][k]!=0)break; if(k==5)ans+=1; } if(i+j==4){ int x = 4,y = 0; for(k=0;k<5;k++){ if(maze[x][y]!=0)break; else{ x--;y++; } } if(k==5)ans++; } if(ans>num){ num = ans; ind = cur[i][j]; } else if(ans==num && ind>cur[i][j])ind = cur[i][j]; maze[i][j] = cur[i][j]; } } } cout<<ind<<endl; }
signed main(){ ios; t = 1; while(t--){ solve(); } }
|