leetcode——537
作者:互联网
复数乘法
class Solution {
public String complexNumberMultiply(String a, String b) {
String x[] = a.split("\\+|i");
String y[] = b.split("\\+|i");//分割字符串,以+和i为分隔符
int a_r = Integer.parseInt(x[0]);//将字符串转化为数字
int a_v = Integer.parseInt(x[1]);
int b_r = Integer.parseInt(y[0]);
int b_v = Integer.parseInt(y[1]);
return (a_r*b_r - a_v*b_v) + "+" + (a_v*b_r + a_r*b_v) + "i";
}
}
标签:String,int,537,字符串,split,parseInt,Integer,leetcode 来源: https://blog.csdn.net/musenh/article/details/100182743