My issue
Why am I getting the output as 0 , 0? It should be 1.000000 and 0.250000.
inputs are —>
2
5 1 1
1 1 1 1 1
2 1 1
1 2
My code
// Update the code below to solve the problem
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int N, A, B;
cin >> N >>A >> B;
int num[N];
for(int i = 0 ; i<N ; i++){
cin >> num[i];
}
int k = 0;
int pa=0;
while (k<=N){
if(A == num[k]){
pa++;
}
k++;
}
int j= 0;
int pb=0;
while ( j<=N){
if(B == num[k]){
pb++;
}
j++;
}
float win = float ((pa/N)*(pb/N));
cout <<win<<endl;
}
}
Learning course: Solve Programming problems using C++
Problem Link: CodeChef: Practical coding for everyone