human
Modify a given array by replacing each element with the sum or product of their digits based on a given condition | Function to modify the given array as per the given conditions.
Traverse the given array arr [ ].
Initialize the count of even and odd digits.
Initialize temp with the current array element.
For count the number of even digits.
Increment the odd count.
Otherwise.
Divide temp by 10.
Performe addition.
Performe multiplication.
Otherwise.
Driver Code"
Solution in Python:
assistant
#Here is code to modify a given array by replacing each element with the sum or product of their digits based on a given condition and the other steps required.
 def evenOdd ( arr , N ) :
	for i in range ( N ) :
		even_digits = 0 ;
		odd_digits = 0 ;
		temp = arr [ i ] ;
		while ( temp ) :
			if ( ( temp % 10 ) & 1 ) :
				odd_digits += 1 ;
			else :
				even_digits += 1 ;
			temp = temp // 10
		if ( even_digits > odd_digits ) :
			res = 0 ;
			while ( arr [ i ] ) :
				res += arr [ i ] % 10 ;
				arr [ i ] = arr [ i ] // 10 ;
			print ( res , end = " ▁ " ) ;
		elif ( odd_digits > even_digits ) :
			res = 1 ;
			while ( arr [ i ] ) :
				res *= arr [ i ] % 10 ;
				arr [ i ] = arr [ i ] // 10
			print ( res , end = " ▁ " ) ;
		else :
			print ( arr [ i ] , end = " ▁ " ) ;
arr = [ 113 , 141 , 214 , 3186 ] ;
N = len ( arr ) ;
evenOdd ( arr , N ) ;