logical problem

Topic description

Suddenly one day, you forgot what day of the week it is today. The Chinese are lucky, so you get eight people and ask each of them to say two sentences. And one of the two sentences is true and the other is false. Maybe the first sentence is true, maybe the second sentence is true. Finally, please make sure that today is the day of the week and output it.

enter description

8 lines, each line is the Arabic numerals of the two days of the week, separated by spaces

output description

A number indicating today's day of the week

sample input

 

1 2
2 6
3 4
5 1
7 7
1 5
1 4
4 2

Sample output

 

7

#include <iostream>
using namespace std;
int main()
{
    int a[8],b[8];
    for (int i = 0; i < 8; i++)
         cin >> a[i] >> b[i];

    
    for (int k = 1; k <= 7; k++)
    {
           int sum = 0;
           for (int i = 0; i < 8; i++)
           {
                                   
            int p = (a[i] == k), q = (b[i] != k);
            sum += (!p && q) || (p && !q);
              }
    
    
    if (sum == 8){
    
        cout << k << endl;
        break;
      }
    }
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324963261&siteId=291194637