第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

求大佬給個注釋 詳細點 謝謝了

求大佬給個注釋 詳細點 謝謝了

C
名不見經傳的小菜鳥 2017-11-20 20:13:20
設計函數分別求兩個一元多項式的乘積與和。輸入格式:輸入分2行,每行分別先給出多項式非零項的個數,再以指數遞降方式輸入一個多項式非零項系數和指數(絕對值均為不超過1000的整數)。數字間以空格分隔。輸出格式:輸出分2行,分別以指數遞降方式輸出乘積多項式以及和多項式非零項的系數和指數。數字間以空格分隔,但結尾不能有多余空格。零多項式應輸出0 0。輸入樣例:4 3 4 -5 2 ?6 1 ?-2 03 5 20 ?-7 4 ?3 1輸出樣例:15 24 -25 22 30 21 -10 20 -21 8 35 6 -33 5 14 4 -15 3 18 2 -6 15 20 -4 4 -5 2 9 1 -2 0Code:#include<stdio.h>#include<stdlib.h>typedef struct node{ ? ? ? ? ? ? ? ? ? ? ??? ? int coef; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// 系數 int exp; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 指數? ? struct node *next; ? ? ? ? ? ? ? ? ? ??}Node;Node *create_node(){ ? ? ? ? ? ? ? ? ? ? ??? ? Node *node = (Node*)malloc(sizeof(Node)); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // Node類型,因為指針在指向結構體成員的時候是指向結構體的首地址? ? node->coef = node->exp = 0; ? ? ? ? ? ?? ? node->next = NULL; ? ? ? ? ? ? ? ? ? ? // 新建指針? ? return node;}void copy_list1_to_list2(Node *list1, Node *list2){? // 將表1抄到表2里 while (list1){ ? ? ? ? ? ? ? ? ? ? ? // 當是list1時 Node *node = create_node(); ? ? ? ?// 定義node 結構體類型的指針 *node 并用create_node()的方法來創(chuàng)建??? node->coef = list1->coef; ? ? ? ? ? node->exp = list1->exp; ? ? ? ? ? ? list2->next = node; ? ? ? ? ? ? ? ?// ? list2 = list2->next; ? ? ? ? ? ? ? //? list1 = list1->next; ? ? ? ? ? ? ? //? }}void read(Node *list){ ? ? ? ? ? ? ? ? ? ? // 讀取Node結構體列表list操作? ? int n; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 指數? ? scanf("%d", &n);? ? while (n--){ ? ? ? ? ? ? ? ? ? ? ? ? ? // 指數遞降 Node *node = create_node(); // 定義node 結構體類型的指針 *node 并用create_node()的方法來創(chuàng)建 scanf ("%d%d", &node->coef, &node->exp); // 輸入系數和指數? ? ? ? list->next = node; ? ? ? ? ? ? ? ? // ?? ? ? ? list = list->next; ? ? ? ? ? ? ? ? //?? ? }}void release(Node *list){ ? ? ? ? ? ? ? ? ?//? ? Node *pre = list, *cur = list->next; ?? ? ? ? ? ? ? ? ? ? ? ? ??? ? while (cur){? ? ? ? free(pre);? ? ? ? pre = cur;? ? ? ? cur = cur->next;? ? }? ? free(pre);}Node* polynomial_add(Node *l1, Node *l2){ Node *l = create_node(); l1 = l1->next, l2 = l2->next; Node *head = l; while (l1 && l2){ if (l1->exp > l2->exp){ Node *node = create_node(); node->coef = l1->coef; node->exp = l1->exp; l->next = node; l1 = l1->next; l = l->next; } else if (l1->exp < l2->exp){ Node *node = create_node(); node->coef = l2->coef; node->exp = l2->exp; l->next = node; l2 = l2->next; l = l->next; } else{ int coef_sum = l1->coef + l2->coef; if (coef_sum == 0){ l1 = l1->next; l2 = l2->next; } else{ Node *node = create_node(); node->coef = coef_sum; node->exp = l1->exp; l1 = l1->next; l2 = l2->next; l->next = node; l = l->next; } } }; if (l1) copy_list1_to_list2(l1, l); if (l2) copy_list1_to_list2(l2, l); return head;}Node *polynomial_multi(Node *l1, Node *l2){ Node *res = create_node(); l1 = l1->next; l2 = l2->next; while (l1) { Node *tmp = create_node(); Node *head = tmp; int coef = l1->coef, exp = l1->exp; copy_list1_to_list2(l2, tmp); tmp = tmp->next; while (tmp) { tmp->coef *= coef; tmp->exp += exp; tmp = tmp->next; } Node *res_new = polynomial_add(head, res); release(res); release(head); res = res_new; l1 = l1->next; } return res;}void print(Node *node) { node ?= node->next; if (!node){ printf("0 0\n"); return; } int flag = 1; while (node){ if (flag){ printf("%d %d", node->coef, node->exp); flag = 0; } else printf(" %d %d", node->coef, node->exp); node = node->next; } putchar(10);}int main(){ //freopen("input.txt", "r", stdin); Node *l1 = create_node(), *l2 = create_node();? ? read(l1);? ? read(l2);? ? Node *l_add = polynomial_add(l1, l2); Node *l_mul = polynomial_multi(l1, l2);? ? print(l_mul);? ? print(l_add); release(l1); release(l2); release(l_add); release(l_mul);? ? return 0;}
查看完整描述

1 回答

?
慕沐4449596

TA貢獻34條經驗 獲得超15個贊

愛莫能助

查看完整回答
1 反對 回復 2017-11-20
  • 1 回答
  • 0 關注
  • 1141 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號