[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;
}

  

posted @ 2014-08-13 17:23  阿牧遥  阅读(290)  评论(0编辑  收藏  举报