本文最后更新于 629 天前,其中的信息可能已经有所发展或是发生改变。

题目描述

从键盘读入n个复数(实部和虚部都为整数)用链表存储,遍历链表求出n个复数的和并输出。

#include<bits/stdc++.h>
using namespace std;
struct Complex {
    int real;
    int image;
};
void input(Complex& c) {
    cin >> c.real >> c.image;
}
int main() {
    int n, x=0, y=0;
    Complex a, b,c;
    cin >> n;
    while (n--) {
        input(a);
        x = x + a.real;
        y = y + a.image;
    }
    cout << x << "+" << y<<"i";
    return 0;
}