[hackerrank]Even Odd Query

https://www.hackerrank.com/contests/w5/challenges

简单题,注意整数的0次方是1,奇数。

#include <iostream>

#include <vector>

using namespace std;



int main() {

    int N;

    cin >> N;

    vector<int> A(N);

    for (int i = 0; i < N; i++) {

        cin >> A[i];

    }

    int Q;

    cin >> Q;

    while (Q--) {

        int x, y;

        cin >> x >> y;

        if (A[x - 1] % 2 != 0) {

            cout << "Odd" << endl;

        } else if (x == y) {

            cout << "Even" << endl;

        } else if (x != N && A[x] == 0){

            cout << "Odd" << endl;

        } else {

            cout << "Even" << endl;

        }

    }

    return 0;

}

  

你可能感兴趣的:(query)