537 Complex Number Multiplication 复数乘法
2024-08-24 06:36:30
详见: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
最新文章
- 【POJ 2187】Beauty Contest 凸包+旋转卡壳
- javascript高级程序设计--笔记01
- spring mvc返回json字符串数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable
- ORA-30036
- IOS CoreData 多表查询demo解析
- 将web应用打成war包发布到服务器
- 使用logback.xml配置来实现日志文件输出
- C语言基础知识小总结(1)
- EC读书笔记系列之18:条款47、48
- CC++初学者编程教程(10) 搭建Android java C/C++ NDK QTforAndroid 开发环境
- [mysql]子查询与连接
- Python快速入门(2)
- ●POJ 1873 The Fortified Forest
- WebRTC技术调研
- Vue框架是什么,有什么特点,怎么用
- CSRF 漏洞原理详解及防御方法
- HDU 1757 A Simple Math Problem(矩阵)
- RabbitMq (1)
- phalcon安装-遇坑php-config is not installed 解决方法
- ubuntu 无法挂载U盘
热门文章
- Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和
- Logcat不显示Application的解决办法
- C/C++的const区别
- 文件的打开函数第一类--fopen()
- 关于 jwTextFiled 的使用说明
- jQuery.ajax各种参数及属性设置
- SpannableStringBuilder 用法浅析以及仿陌陌表情
- <;%@ Page Language=";C#"; AutoEventWireup=";true"; CodeFile=";Login.aspx.cs"; Inherits=";Login"; %>;
- html和xml的区别
- 使用JavaScript选择GridView行的方法汇总