cpp solution with sscanf


  • 0
    B
    string complexNumberMultiply(string a, string b) {
        int ar, ai, br, bi; 
        sscanf(a.c_str(),"%d+%di", &ar, &ai);
        sscanf(b.c_str(), "%d+%di", &br, &bi);
        return to_string(ar*br-ai*bi) + "+" + to_string(ar*bi+br*ai) + "i";
    }

Log in to reply
 

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