Skip to content
Programming101
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

HackerEarth Sherlock and XOR problem solution

YASH PAL, 31 July 2024
In this HackerEarth Sherlock and XOR problem solution, You are given an array A1, A2…AN. You have to tell how many pairs (i, j) exist such that 1 ≤ i < j ≤ N and Ai XOR Aj is odd.
HackerEarth Sherlock and XOR problem solution

HackerEarth Sherlock and XOR problem solution.

#include <cstdlib>
#include <stdio.h>
#include <cstring>
#include <complex>
#include <vector>
#include <cmath>
#include <ctime>
#include <iostream>
#include <numeric>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <iomanip>
#include <utility>
#include <locale>
#include <sstream>
#include <string>
#include <istream>
#include <ostream>
#include<assert.h>

using namespace std;

#define FOR(i,n) for(i=0;i<n;i++)
#define FORI(i,a,n) for(i=a;i<n;i++)
#define FORC(it,C) for(it=C.begin();it!=C.end();it++)
#define scanI(x) scanf("%d",&x)
#define scanD(x) scanf("%lf",&x)
#define print(x) printf("%dn",x)
#define ll long long
#define number32 4294967296ull
#define MAX 100001
#define len(s) s.length()
#define ff first
#define ss second
#define IN(A, B, C) (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
using namespace std;

typedef map<int,int> Mii;
typedef map<char,int> Mci;
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<int> vc;
typedef vector<ll> vl;

typedef map<int,int>::iterator Miii;
typedef map<char,int>::iterator Mcii;

ll A[MAX+1];
int main()
{
int t,i;
int n;
cin>>t;
AIN(t,1,10);
ll ceven,codd;
ll ans;
while(t--)
{
ceven=0;
codd=0;
cin>>n;
AIN(n,1,100000);
FOR(i,n)
{
cin>>A[i];
AIN(A[i],0,1000000000);
if(A[i]%2==0)
{
ceven++;
}
else codd++;

}
ans=ceven*codd;
cout<<ans<<endl;
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes