C user is disappearing...


  • 0
    W
    char* complexNumberMultiply(char* a, char* b) {
        int i, len;
    	int x1,x2,y1,y2,x,y;
    	char *ans = NULL;
    
    	ans = (char*) malloc(100);
    
    	len = strlen(a);
    	for(i = 0; i < len; ++i)
    	{
    		if(a[i] == '+') a[i] = ' ';
    	}
    	a[len-1] = 0;
    	sscanf(a, "%d %d", &x1, &y1);
    
    	len = strlen(b);
    	for(i = 0; i < len; ++i)
    	{
    		if(b[i] == '+') b[i] = ' ';
    	}
    	b[len-1] = 0;
    	sscanf(b, "%d %d", &x2, &y2);
    
    	x = x1*x2 - y1*y2;
    	y = x1*y2 + x2*y1;
    
    	sprintf(ans, "%d+%di", x, y);
    	return ans;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.