We are here to help. We can find 2 sub parts in your question:
- Whats wrong in this code?
- Why its been identified as wrong answer by the online judge?
Let us first answer the question part no 1. So, wrong is:
#include <bits/stdc++.h>
should never be used. It is a non standard C++ header file. Not known by most compilers. Additionally, it is even not used/needed
#include <cmath>
is not used/needed
using namespace std;
should never be used. Instead, always use fully qualified names
ios_base::sync_with_stdio(false);
has no meaning and is not necessary at all in this context
cin.tie(NULL);
has no meaning and is not necessary at all in this context
- all variables should be unsigned
- all variables should have a meaningful name, eg. "t" should be named "numberOfTestCases"
- You could consider the usage of a chained extraction operation. Instead of the 6 lines
cin >> ...
you could have only one statement std::cin >> r1 >> w1 >> c1 >> r2 >> w2 >> c2;
Then, next, question part no 2. In my understanding, your solution approach is wrong. If you want to know, which player is better, you have to look at the statics one by one.
You could introduce a "betterCounter" and then compare each statistic with the other statistic. And if statistic from A is better than that from B, you could increment this value.
So, we need to compare. Something like "c1 > c2". The result of that is a boolean value. But very conviently, it can be converted to an integer. And to make this conversion clear, we could multiply the comparison with 1. Something like: (c1 > C2) * 1
.
Then we could come up with a solution like the following (´this is one of millions of possible implementations)
#include <iostream>
int main() {
// Get the number of testcases
unsigned int numberOfTestCases{};
std::cin >> numberOfTestCases;
// Now operate all test cases
while (numberOfTestCases--) {
// Definition of statistic variables
unsigned int playerA_StatisticR{}, playerA_StatisticW{}, playerA_StatisticC{},
playerB_StatisticR{}, playerB_StatisticW{}, playerB_StatisticC{};
// Read all values
std::cin >> playerA_StatisticR >> playerA_StatisticW >> playerA_StatisticC >>
playerB_StatisticR >> playerB_StatisticW >> playerB_StatisticC;
// Calculate result for player A and player B
const unsigned int sumPlayerAisBetter = (playerA_StatisticR > playerB_StatisticR) * 1 +
(playerA_StatisticW > playerB_StatisticW) * 1 +
(playerA_StatisticC > playerB_StatisticC) * 1;
const unsigned int sumPlayerBisBetter = (playerB_StatisticR > playerA_StatisticR) * 1 +
(playerB_StatisticW > playerA_StatisticW) * 1 +
(playerB_StatisticR > playerA_StatisticC) * 1;
// Show result
if (sumPlayerAisBetter > sumPlayerBisBetter ) std::cout << "A\n";
if (sumPlayerBisBetter > sumPlayerAisBetter ) std::cout << "B\n";
}
return 0;
}