Check if quantities of 3 distinct colors can be converted to a single color by given merge | C ++ program for the above approach ; Function to check whether it is possible to do the operation or not ; Calculate modulo 3 of all the colors ; Check for any equal pair ; Otherwise ; Driver Code ; Given colors ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPossible ( int r , int b , int g ) { r = r % 3 ; b = b % 3 ; g = g % 3 ; if ( r == b b == g g == r ) { return true ; } else { return false ; } } int main ( ) { int R = 1 , B = 3 , G = 6 ; if ( isPossible ( R , B , G ) ) { cout << " Yes " << endl ; } else { cout << " No " << endl ; } return 0 ; }