第四次homeworkA.cpp

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

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

View Full Document Right Arrow Icon
#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) {
Image of page 1

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

View Full Document Right Arrow Icon
// 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; }
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern