# 第四次homeworkA.cpp - #include using...

This preview shows pages 1–3. Sign up to view the full content.

#include <iostream> using namespace std; int main() { int a[20][20]; int count1, count2; bool haveWinner; int n; cin >> n; while (n--) { haveWinner = true; for (int i = 0; i < 19; i++) for (int k = 0; k < 19; k++) cin >> a[i][k]; // Judge the result First, horizontal for (int i = 0; i < 19; i++) { count1 = 0; count2 = 0; for (int k = 0; k < 19; k++) { if (a[i][k] == 1) { count1++; count2 = 0; } else if (a[i][k] == 2) { count1 = 0; count2++; } else { count1 = 0; count2 = 0; } if (count1 == 5) { // check the next position if (k == 18) { cout << "1" << endl << i + 1 << " " << k - 3 << endl; haveWinner = false; break; } else { if (a[i][k + 1] == 1) continue; else { cout << "1" << endl << i + 1 << " " << k - 3 << endl; haveWinner = false; break; } } } if (count2 == 5) {

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
// check the next position if (k == 18) { cout << "2" << endl << i + 1 << " " << k - 3 << endl; haveWinner = false; break; } else { if (a[i][k + 1] == 2) continue; else { cout << "2" << endl << i + 1 << " " << k - 3 << endl; haveWinner = false; break; } } } } } // Judge the vertical lines for (int i = 0; i < 19; i++) { count1 = 0; count2 = 0; for (int k = 0; k < 19; k++) { if (a[k][i] == 1) { count1++; count2 = 0; } else if (a[k][i] == 2) { count1 = 0; count2++; } else { count1 = 0; count2 = 0; } if (count1 == 5) { // check the next position if (k == 18) { cout << "1" << endl << k - 3 << " " << i + 1 << endl; haveWinner = false; break; } else { if (a[k + 1][i] == 1) continue; else { cout << "1" << endl << k - 3 << " " << i + 1 << endl; haveWinner = false; break; }
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern