document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.util.*;
  2. public class uva10813 {
  3.     public static void main(String [] args) {
  4.         Scanner scn = new Scanner(System.in);
  5.         int n = scn.nextInt();
  6.         for(int x=0;x<n;x++) {
  7.             int arr[][] = new int[5][5];
  8.             for(int y=0;y<5;y++) {
  9.                 for(int z=0;z<5;z++) {
  10.                     if(y==2 && z==2)
  11.                         arr[y][z]=0;
  12.                     else
  13.                         arr[y][z]=scn.nextInt();
  14.                 }
  15.             }
  16.             boolean bool = true;
  17.             int lessFive = 0;
  18.             while(lessFive<75) {
  19.                 int a = scn.nextInt();
  20.                 lessFive++;
  21.                 if(bool==true) {
  22.                     int count = 0;
  23.                    
  24.                     boolean boolCheck = true;
  25.                     for(int y=0;y<5;y++) {
  26.                         for(int z=0;z<5;z++) {
  27.                             if(a == arr[y][z])
  28.                                 arr[y][z] = 0;
  29.                         }
  30.                     }
  31.                    
  32.                     if(boolCheck == true) {
  33.                         for(int y=0;y<5;y++) {
  34.                             count = 0;
  35.                             for(int z=0;z<5;z++) {
  36.                                 if(arr[y][z] == 0)
  37.                                     count++;
  38.                             }
  39.                             if(count == 5) {
  40.                                 System.out.println("BINGO after "+lessFive +" numbers announced");
  41.                                 bool = false;
  42.                                 boolCheck = false;
  43.                                 y=5;
  44.                                
  45.                             }
  46.                         }
  47.                     }
  48.                     if(boolCheck == true) {
  49.                         for(int y=0;y<5;y++) {
  50.                             count = 0;
  51.                             for(int z=0;z<5;z++) {
  52.                                 if(arr[z][y] == 0)
  53.                                     count++;
  54.                             }
  55.                             if(count == 5) {
  56.                                 System.out.println("BINGO after "+lessFive +" numbers announced");
  57.                                 bool = false;
  58.                                 boolCheck = false;
  59.                                 y=5;
  60.                                
  61.                             }
  62.                         }
  63.                     }
  64.                     if(boolCheck == true) {
  65.                         count = 0;
  66.                         for(int y=0;y<5;y++) {
  67.                             if(arr[y][y] == 0)
  68.                                 count++;
  69.                         }
  70.                         if(count == 5) {
  71.                             System.out.println("BINGO after "+lessFive +" numbers announced");
  72.                             bool = false;
  73.                             boolCheck = false;
  74.                            
  75.                         }
  76.                     }
  77.                     if(boolCheck == true) {
  78.                         count = 0;
  79.                         for(int y=4;y>-1;y--) {
  80.                             if(arr[4-y][y] == 0)
  81.                                 count++;
  82.                         }
  83.                         if(count == 5) {
  84.                             System.out.println("BINGO after "+lessFive +" numbers announced");
  85.                             bool = false;
  86.                             boolCheck = false;
  87.                            
  88.                         }
  89.                     }
  90.                 }
  91.             }
  92.         }
  93.     }
  94. }
');