fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int bingo[5][5];
  5. bool checked[5][5];
  6.  
  7. bool isBingo() {
  8. for(int i = 0; i < 5; i++) {
  9. // baris
  10. if(checked[i][0] && checked[i][1] && checked[i][2]
  11. && checked[i][3] && checked[i][4])
  12. return true;
  13. // kolom
  14. if(checked[0][i] && checked[1][i] && checked[2][i]
  15. && checked[3][i] && checked[4][i])
  16. return true;
  17. }
  18. if(checked[0][0] && checked[1][1] && checked[2][2]
  19. && checked[3][3] && checked[4][4])
  20. return true;
  21. if(checked[0][4] && checked[1][3] && checked[2][2]
  22. && checked[3][1] && checked[4][0])
  23. return true;
  24. return false;
  25. }
  26.  
  27. int main() {
  28. int n;
  29. cin >> n;
  30. while(n--) {
  31. for(int i = 0; i < 5; i++)
  32. for(int j = 0; j < 5; j++) {
  33. if(i == 2 && j == 2) {
  34. checked[i][j] = true;
  35. bingo[i][j] = 0;
  36. }
  37. else {
  38. checked[i][j] = false;
  39. cin >> bingo[i][j];
  40. }
  41. }
  42. bool win = false;
  43. for(int turn = 1; turn <= 75; turn++) {
  44. int num;
  45. cin >> num;
  46. if(win) continue;
  47. for(int i = 0; i < 5; i++)
  48. for(int j = 0; j < 5; j++)
  49. if(bingo[i][j] == num) {
  50. checked[i][j] = true;
  51. if(isBingo()) {
  52. win = true;
  53. cout << "BINGO after " << turn << " numbers announced" << endl;
  54. }
  55. }
  56. }
  57. }
  58. return 0;
  59. }
Success #stdin #stdout 0.01s 5284KB
stdin
1
10 17 39 49 64
12 21 36 55 62
14 25 52 70
7 19 32 56 68
5 24 34 54 71
1 2 3 4 5 6 7 8 9 10
11 12 13 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 73 74 75 14
stdout
BINGO after 24 numbers announced