最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

求大佬給個(gè)注釋 詳細(xì)點(diǎn) 謝謝了

求大佬給個(gè)注釋 詳細(xì)點(diǎn) 謝謝了

設(shè)計(jì)函數(shù)分別求兩個(gè)一元多項(xiàng)式的乘積與和。輸入格式:輸入分2行,每行分別先給出多項(xiàng)式非零項(xiàng)的個(gè)數(shù),再以指數(shù)遞降方式輸入一個(gè)多項(xiàng)式非零項(xiàng)系數(shù)和指數(shù)(絕對(duì)值均為不超過(guò)1000的整數(shù))。數(shù)字間以空格分隔。輸出格式:輸出分2行,分別以指數(shù)遞降方式輸出乘積多項(xiàng)式以及和多項(xiàng)式非零項(xiàng)的系數(shù)和指數(shù)。數(shù)字間以空格分隔,但結(jié)尾不能有多余空格。零多項(xiàng)式應(yīng)輸出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; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// 系數(shù) int exp; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 指數(shù)? ? struct node *next; ? ? ? ? ? ? ? ? ? ??}Node;Node *create_node(){ ? ? ? ? ? ? ? ? ? ? ??? ? Node *node = (Node*)malloc(sizeof(Node)); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // Node類型,因?yàn)橹羔樤谥赶蚪Y(jié)構(gòu)體成員的時(shí)候是指向結(jié)構(gòu)體的首地址? ? node->coef = node->exp = 0; ? ? ? ? ? ?? ? node->next = NULL; ? ? ? ? ? ? ? ? ? ? // 新建指針? ? return node;}void copy_list1_to_list2(Node *list1, Node *list2){? // 將表1抄到表2里 while (list1){ ? ? ? ? ? ? ? ? ? ? ? // 當(dāng)是list1時(shí) Node *node = create_node(); ? ? ? ?// 定義node 結(jié)構(gòu)體類型的指針 *node 并用create_node()的方法來(lái)創(chuàng)建??? node->coef = list1->coef; ? ? ? ? ? node->exp = list1->exp; ? ? ? ? ? ? list2->next = node; ? ? ? ? ? ? ? ?// ? list2 = list2->next; ? ? ? ? ? ? ? //? list1 = list1->next; ? ? ? ? ? ? ? //? }}void read(Node *list){ ? ? ? ? ? ? ? ? ? ? // 讀取Node結(jié)構(gòu)體列表list操作? ? int n; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 指數(shù)? ? scanf("%d", &n);? ? while (n--){ ? ? ? ? ? ? ? ? ? ? ? ? ? // 指數(shù)遞降 Node *node = create_node(); // 定義node 結(jié)構(gòu)體類型的指針 *node 并用create_node()的方法來(lái)創(chuàng)建 scanf ("%d%d", &node->coef, &node->exp); // 輸入系數(shù)和指數(shù)? ? ? ? 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貢獻(xiàn)34條經(jīng)驗(yàn) 獲得超15個(gè)贊

愛(ài)莫能助

查看完整回答
1 反對(duì) 回復(fù) 2017-11-20
  • 1 回答
  • 0 關(guān)注
  • 1151 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)