#include #include using namespace std;

// 判断一个数是偶数还是奇数 bool isEven(int num) { return num % 2 == 0; }

int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector nums(n); for (int i = 0; i < n; i++) { cin >> nums[i]; }

    // 定义两个变量分别表示小A和小B的得分
    int scoreA = 0;
    int scoreB = 0;

    // 对每个数进行判断
    for (int i = 0; i < n; i++) {
        // 如果是偶数,则小A得分加上这个数
        if (isEven(nums[i])) {
            scoreA += nums[i];
        }
        // 如果是奇数,则小B得分加上这个数
        else {
            scoreB += nums[i];
        }
    }

    // 比较得分大小,输出结果
    if (scoreA > scoreB) {
        cout << 'A' << endl;
    } else if (scoreA < scoreB) {
        cout << 'B' << endl;
    } else {
        cout << 'C' << endl;
    }
}
return 0;

}

C++实现取数游戏获胜者判定 - 优化代码并输出结果

原文地址: https://www.cveoy.top/t/topic/qoER 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录