Count of ordered triplets ( R , G , B ) in a given original string | C ++ code for the above program ; function to count the ordered triplets ( R , G , B ) ; count the B ( blue ) colour ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countTriplets ( string color ) { int result = 0 , Blue_Count = 0 ; int Red_Count = 0 ; for ( char c : color ) { if ( c == ' B ' ) Blue_Count ++ ; } for ( char c : color ) { if ( c == ' B ' ) Blue_Count -- ; if ( c == ' R ' ) Red_Count ++ ; if ( c == ' G ' ) result += Red_Count * Blue_Count ; } return result ; } int main ( ) { string color = " RRGGBBRGGBB " ; cout << countTriplets ( color ) ; return 0 ; }