当前位置:网站首页>6-40 constructing ordered sparse polynomial chained storage
6-40 constructing ordered sparse polynomial chained storage
2022-06-22 09:36:00 【Xia ~ Chen】
This problem constructs a chain stored procedure of ordered sparse polynomials , The input polynomial has two terms : Coefficients and exponents .
Be careful : The input exponent is unordered . Please save polynomials in chained storage .
Output in the order of the exponent from small to large .
To simplify the construction of linked list , The default construction linked list is the supervised single linked list .
Function interface definition :
ptr creat();creat Function is to construct linked list .
Sample referee test procedure :
#include <stdio.h>
#include <malloc.h>
typedef struct node
{
float ceof;
int exp;
struct node *next;
}node,*ptr;
ptr creat();
void output(ptr h)
{
ptr p;
p=h->next;
while(p!=NULL)
{
printf("%+.1fx^%d",p->ceof,p->exp);
p=p->next;
}
printf("\n");
}
int main()
{
ptr head;
head=creat();
output(head);
return 0;
}
/* Please fill in the answer here */sample input :
100.3 10
90 5
18 92
21.8 2
-19 0
0 0No blank lines at the end
sample output :
-19.0x^0+21.8x^2+90.0x^5+100.3x^10+18.0x^92Ideas : Construct a chain storage structure , Then make the input data orderly according to the index , Here I offer two ideas : One is that we sort while inputting , One is to sort after we have constructed it , Below I provide the algorithm of sorting while inputting
, Code up
ptr creat()
{
ptr p;
p = (ptr)malloc(sizeof(node));// Application node space
node* q, * pre, * s;
p ->next = NULL;// The tail node is empty
while(1)
{
s = (ptr)malloc(sizeof(node));
scanf("%f %d", &s->ceof, &s->exp);// The input values
pre = p;
q = p -> next;
while (q && q->exp < s->exp)// Edge input edge comparison
{
pre = q;
q = q->next;
}
if(s->ceof==0)// Cycle end condition , That is, the input value and index are 0
break;
s->next = q;
pre->next = s;
}
}边栏推荐
- [模板] kmp
- [hdu] P6964 I love counting
- The solution for golang Mongo go driver find() to read 101 records by default
- day260:只出现一次的数字 III
- Embedded development terminology concept summary
- The difference between single bracket and double bracket in shell
- 值(址)传递,看清名字,别掉沟里
- Template engine, making interaction elegant
- [Luogu] P2887 Sunscreen G
- 稀疏数组^创建^还原^存盘^取盘--全家桶
猜你喜欢

Introduction to code audit learning notes

機器學習|nltk_Data下載錯誤|nltk的stopwords語料下載錯誤解决方法

Summary and future prospect of transfer learning | community essay solicitation

Performance optimization topics

支付-订单案例构建

Machine learning | nltk_ Data download error |nltk's stopwords corpus download error solution

Mapping multiple exit servers on ENSP

DHCP Relay

File expert ---multer

Apprentissage automatique | nltk Erreur de téléchargement des données | solution d'erreur de téléchargement du corpus stopwords pour nltk
随机推荐
rewrite? Reload? Are you dizzy?
Error in PHP installation of Pagoda: libcares so. 2: cannot open shared object file: No such file or directory
Final典型案例
[hdu] P7079 Pty loves lines
Comparison of interface abstract classes
See how much volatile you know
When golang operates mongodb, vscode prompts primitive E composite literal uses unlocked fields
Lexical Sign Sequence
The time difference between IIS7 log and system time is 8 hours. Use logparser to solve the problem
Audio and video 2022 beauty function introduction teach you to play video beauty
Logistic regression and linear regression
Mapping Multi - export Server on ENSP
Opencv daily function histogram correlation (3)
[node] theory + practice enables you to win sessions and cookies
pytorch的模块使用:线性模型(未完成)
编译basalt时出现的报错
Function summary (1)
C language question brushing | three item operation to realize capital judgment (16)
How C processes use non static methods
Brush questions in C language | judge whether a certain year is only a leap year (15)