详见:https://leetcode.com/problems/complex-number-multiplication/description/

C++:

class Solution {
public:
string complexNumberMultiply(string a, string b)
{
int n1 = a.size(), n2 = b.size();
auto p1 = a.find_last_of("+"), p2 = b.find_last_of("+");
int a1 = stoi(a.substr(0, p1)), b1 = stoi(b.substr(0, p2));
int a2 = stoi(a.substr(p1 + 1, n1 - p1 - 2));
int b2 = stoi(b.substr(p2 + 1, n2 - p2 - 2));
int r1 = a1 * b1 - a2 * b2, r2 = a1 * b2 + a2 * b1;
return to_string(r1) + "+" + to_string(r2) + "i";
}
};

参考:http://www.cnblogs.com/grandyang/p/6660437.html

最新文章

  1. 【POJ 2187】Beauty Contest 凸包+旋转卡壳
  2. javascript高级程序设计--笔记01
  3. spring mvc返回json字符串数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable
  4. ORA-30036
  5. IOS CoreData 多表查询demo解析
  6. 将web应用打成war包发布到服务器
  7. 使用logback.xml配置来实现日志文件输出
  8. C语言基础知识小总结(1)
  9. EC读书笔记系列之18:条款47、48
  10. CC++初学者编程教程(10) 搭建Android java C/C++ NDK QTforAndroid 开发环境
  11. [mysql]子查询与连接
  12. Python快速入门(2)
  13. ●POJ 1873 The Fortified Forest
  14. WebRTC技术调研
  15. Vue框架是什么,有什么特点,怎么用
  16. CSRF 漏洞原理详解及防御方法
  17. HDU 1757 A Simple Math Problem(矩阵)
  18. RabbitMq (1)
  19. phalcon安装-遇坑php-config is not installed 解决方法
  20. ubuntu 无法挂载U盘

热门文章

  1. Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和
  2. Logcat不显示Application的解决办法
  3. C/C++的const区别
  4. 文件的打开函数第一类--fopen()
  5. 关于 jwTextFiled 的使用说明
  6. jQuery.ajax各种参数及属性设置
  7. SpannableStringBuilder 用法浅析以及仿陌陌表情
  8. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
  9. html和xml的区别
  10. 使用JavaScript选择GridView行的方法汇总