⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 duo.cpp

📁 这是学校ACM程序设计大赛的题目,拿出来大家算是当练习
💻 CPP
字号:

#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
	int xis;
	int chis;
	struct node *next;
}lnode;


lnode *create_l(lnode *head, int x, int c)
{
	lnode *p;
	p=(lnode *)malloc(sizeof(struct node));
	p->xis=x;
	p->chis=c;
	p->next=NULL;
	if(head==NULL)
	{
		head=p;
	}
	else
	{
		p->next=head;
		head=p;
	}
	return head;
}

void print_l(lnode *head)
{
	lnode *p=(lnode *)malloc(sizeof(struct node));
	p=head;
	while(p!=NULL)
	{
		printf("%d ",p->chis);
		printf("%d ",p->xis);
		printf("\n");
		p=p->next;
	}
}

void print_s(lnode *head,int n)
{
	FILE *fp;
	fp=fopen("c.out","a");
	int index=0;
	int *array=(int *)malloc(n*sizeof(int));
	if(n==0)
		printf("0\n");
	else
	{
		while((head->chis)>=n)
		{
			lnode *q;
			q=NULL;
			q=head;
			for(int i=head->chis; i>((head->chis)-n); i--)
				q=q->next;
			q->xis=((q->xis)-(head->xis));
			head=head->next;
		}

		while(head!=NULL)
		{
			array[index]=head->xis;
			index++;
			head=head->next;
		}
		for(int j=index-1; j>=0; j--)
			if(j==0)printf("%d\n",array[j]); else printf("%d ",array[j]);
		//printf("\n");
	}
}

void main()
{
	lnode *headc,*headb;
	headc=NULL;
	headb=NULL;
	FILE *fp;
	if((fp=fopen("Polyn.in","r"))==NULL)
	{
		printf("can't open file\n");
		exit(0);
	}
	int maxc,maxb;
	fscanf(fp,"%d %d",&maxb,&maxc);
	while(maxb!=-1&&maxc!=-1)
	{
		int num;
		for(int i=0; i<=maxb; i++)
		{
			fscanf(fp,"%d",&num);
			headb=create_l(headb,num,i);
		}
	//	print_l(headb);
	//	printf("---\n");
		print_s(headb,maxc);
		headb=NULL;
		fscanf(fp,"%d %d",&maxb,&maxc);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -