#include <bits/stdc++.h> #define debuga(v, i) cout << #v << "[" << i << "]" << " = " << v[i] << '\n'; #define debug(x) cout << #x << " = " << x << '\n'; #define PI 3.1415926 using namespace std; const int N = 1010; typedef struct node { int real; int imaginary; struct node *next; }Node; Node *creatnode(Node *head, int real, int imaginary) { Node *p = (Node *)malloc(sizeof(Node)); p -> real = real; p -> imaginary = imaginary; p -> next = NULL; if (!p) { cout << "申请内存失败" << '\n'; exit(0); } if (!head) { head = p; } else { p -> next = head; head = p; } return head; } void solve() { int real, imaginary; int sum1 = 0, sum2 = 0; char sym; Node *head = NULL; //这里要初始化,不然就RunError for (int i = 0; i < 10; i ++ ) { cin >> real >> imaginary; head = creatnode(head, real, imaginary); } Node *p = head; while (p) { sum1 += p -> real; sum2 += p -> imaginary; p = p -> next; } if (sum2 < 0) sym = '-'; else sym = '+'; cout << sum1 << sym << sum2 << 'i'; } int main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; // cin >> T; while (T --) { solve(); } return 0; }
0.0分
0 人评分
The 3n + 1 problem (C++代码)(所有测试数据都小于等于1000,,说好的1000000之内呢)浏览:1124 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:778 |
程序员的表白 (C语言代码)浏览:1461 |
奖学金 (C++代码)浏览:2053 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:778 |
C语言训练-阶乘和数* (C语言代码)-------- 呆板写法浏览:1396 |
母牛的故事 (C语言代码)浏览:1450 |
DNA (C语言代码)浏览:564 |
1642题解浏览:784 |
Minesweeper (C语言描述,蓝桥杯)浏览:1176 |