537 Complex Number Multiplication 复数乘法
详见: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
537 Complex Number Multiplication 复数乘法的更多相关文章
- LC 537. Complex Number Multiplication
		Given two strings representing two complex numbers. You need to return a string representing their m ... 
- 【LeetCode】537. Complex Number Multiplication 解题报告(Python & C++)
		作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 日期 题目地址:https://leetcode.com/pr ... 
- 537. Complex Number Multiplication
		题目大意: 给出a, b两个用字符串表示的虚数,求a*b 题目思路: 偷了个懒,Python3的正则表达式匹配了一下,当然acm里肯定是不行的 class Solution: def complexN ... 
- LeetCode 537. 复数乘法(Complex Number Multiplication)
		537. 复数乘法 537. Complex Number Multiplication 题目描述 Given two strings representing two complex numbers ... 
- [Swift]LeetCode537. 复数乘法 | Complex Number Multiplication
		Given two strings representing two complex numbers. You need to return a string representing their m ... 
- [LeetCode] Complex Number Multiplication 复数相乘
		Given two strings representing two complex numbers. You need to return a string representing their m ... 
- LeetCode Complex Number Multiplication
		原题链接在这里:https://leetcode.com/problems/complex-number-multiplication/description/ 题目: Given two strin ... 
- [leetcode-537-Complex Number Multiplication]
		Given two strings representing two complex numbers. You need to return a string representing their m ... 
- ural 1748 The Most Complex Number  和 丑数
		题目:http://acm.timus.ru/problem.aspx?space=1&num=1748 题意:求n范围内约数个数最多的那个数. Roughly speaking, for a ... 
随机推荐
- 安装Nginx四层负载均衡
			Nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信. stream模块默认不安装的,需要手动添加参数:–with-stream,官方下载地址:downlo ... 
- ansible 基础知识
			英文官网,值得拥有! http://docs.ansible.com/ansible/list_of_files_modules.html# 摘自: http://blog.csdn.net/b624 ... 
- hdu 1358 Period(kmp求一个串的重复子串)
			题意:统计单串中从某个位置以前有多少重复的串 思路:kmp模板 #include<iostream> #include<stdio.h> #include<string. ... 
- ubuntu下安装cpython 0.2x
			Quick installation of cython: Step 1: Update system: sudo apt-get update Step 2: Install: cython Ate ... 
- Linux删除乱码非空目录
			# ls -li 总用量 drwxr-xr-x root root 2月 : 2.1 -rw-rw-r-- binwen binwen 2月 : Htc_常用软件.zip drwxr-xr-x roo ... 
- nginx开发_ngx_http_script源码解析
			功能简介 nginx中有很多配置项支持以变量的形式存在,在运行时根据实时值进行处理.例如如下配置: location / { sub_filter '<a href="http://1 ... 
- hihoCoder2月29日(字符串模拟)
			时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年: ... 
- Rikka with Sequence
			题意: 给一长度为n的序列,维护三个操作:区间开根,区间加,区间求和. 解法: 注意到本题关键在于区间开根: 对于一个数字,只要进行$O(loglogT)$次开根即会变为1. 考虑线段树,对于线段数上 ... 
- 3-2带命令行参数的Java
			命令行参数: 主方法Main 小括号里面的内容就是命令参数: String[] args class ArgsDemo{ public static void main(String[] args){ ... 
- HTML学习笔记(二)HTML格式化
			很多标签都可以用来改变文本的外观,并为文本关联其隐藏的含义.总地来说,这些标签可以分成两类:基于内容的样式(content-based style)和物理样式(physical style). 一.基 ... 
