human
Multiply N complex numbers given as strings | Function which returns the in digit format.
a : real b : imaginary.
sa : sign of a sb : sign of b.
Extract the real number.
Extract the imaginary part.
If size == 1 means we reached at result.
Extract the first two elements.
Remove them.
Calculate and store the real part.
Calculate and store the imaginary part.
Append the real part.
Append the imaginary part.
Insert into vector.
Driver code"
Solution in Python:
assistant
#Here is code to multiply N complex numbers given as strings and the other steps required.
 def findnum ( s1 ) :
	v = [ ]
	a = 0
	b = 0
	sa = 0
	sb = 0
	i = 0
	if ( s1 [ 0 ] == ' - ' ) :
		sa = 1
		i = 1
	while ( s1 [ i ] . isdigit ( ) ) :
		a = a * 10 + ( int ( s1 [ i ] ) )
		i += 1
	if ( s1 [ i ] == ' + ' ) :
		sb = 0
		i += 1
	if ( s1 [ i ] == ' - ' ) :
		sb = 1
		i += 1
	while ( i < len ( s1 ) and s1 [ i ] . isdigit ( ) ) :
		b = b * 10 + ( int ( s1 [ i ] ) )
		i += 1
	if ( sa ) :
		a *= - 1
	if ( sb ) :
		b *= - 1
	v . append ( a )
	v . append ( b )
	return v
def complexNumberMultiply ( v ) :
	while ( len ( v ) != 1 ) :
		v1 = findnum ( v [ 0 ] )
		v2 = findnum ( v [ 1 ] )
		del v [ 0 ]
		del v [ 0 ]
		r = ( v1 [ 0 ] * v2 [ 0 ] - v1 [ 1 ] * v2 [ 1 ] )
		img = v1 [ 0 ] * v2 [ 1 ] + v1 [ 1 ] * v2 [ 0 ]
		res = " "
		res += str ( r )
		res += ' + '
		res += str ( img ) + ' i '
		v . insert ( 0 , res )
	return v [ 0 ]
if __name__ == ' _ _ main _ _ ' :
	n = 3
	v = [ "3 + 1i " , "2 + 1i " , " - 5 + - 7i " ]
	print ( complexNumberMultiply ( v ) )