首页 > 试题广场 >

复数

[编程题]复数
  • 热度指数:4540 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
编写一个复数类,有构造函数,能对复数初始化重载加法操作符并按a+bi 的形式输出。

输入描述:
输入第一行表示测试用例的个数m,接下来m行每行有4个用空格隔开的整数,分别表示2个复数的实部和虚部。


输出描述:
输出m行。按a+bi或者a-bi的格式输出,表示两个复数相加的和。
示例1

输入

1
3 4 1 -2

输出

4+2i

备注:
注意虚部为负数时的输出。
头像 philos
发表于 2021-03-23 11:16:15
简单的重载运算符 #include<iostream> using namespace std; class Complex{ public: int a, b; Complex(int _a, int _b) : a(_a), b(_b) {} Compl 展开全文
头像 牛客440904392号
发表于 2024-10-04 02:03:25
#include <iostream> using namespace std; struct Complex { int real, imag; Complex operator+(const Complex &other) { int real 展开全文
头像 牛客182054830号
发表于 2023-03-27 08:47:18
#include <iostream> using namespace std; class Complex { private: int a; int b; public: Complex(int i = 0, int j = 0) { 展开全文
头像 KDDA十三尧十三
发表于 2022-02-15 21:48:24
#include<iostream> using namespace std; class Complex {     public:     double a,b; 展开全文
头像 笑川不吃香菜
发表于 2024-03-17 14:49:14
#include <iostream> using namespace std; class complex{ public: int real; int unreal; complex(int a,int b){ 展开全文
头像 在offer比较的肖恩很胆小
发表于 2024-03-09 11:13:39
#include <iostream> using namespace std; class ComplexNumber { friend ostream& operator<<(ostream&, ComplexNumber&); pu 展开全文
头像 爱吃的懒羊羊离上岸不远了
发表于 2025-03-16 21:24:31
#include <iostream> using namespace std; class FU{ public: int real; int vir; FU operator+(FU &fu1) { FU newF; 展开全文
头像 牛客475334106号
发表于 2024-03-07 18:04:58
#include <stdio.h> int main() { int m,a1,b1,a2,b2; scanf("%d", &m); while (m--) { scanf("%d%d%d%d", 展开全文

问题信息

上传者:小小
难度:
30条回答 3417浏览

热门推荐

通过挑战的用户

查看代码
复数