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

📄 1a.c

📁 《数据结构-使用C语言》第三版
💻 C
字号:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>

typedef int DataType;

#include"DLNode.h"

int main()
{
	DLNode *heada, *headb, *headc, *p;
	
	void add(DLNode *la, DLNode *lb, DLNode *lc);
	char str[100];
	int i, j, x, t, la, lb;
	
	while(1)
	{
		ListInitiate(&heada);
		ListInitiate(&headb);
		ListInitiate(&headc);
		
		scanf("%s",str);
		j=strlen(str);
		
		if(str[0]=='-')heada->data=0;
		else heada->data=1;
		
		for(i=1;i<j;i++)
		{
			if(str[i]==';')break;
			t=0;
			while(str[i]!=',')
			{
				t+=10*t+str[i]-'0';
				i++;
			}
			if(la->data==0)t=-t;
			if(ListInsert(heada, 0, t)==0)
			{
				printf("error!");
				return ;
			}
		}
		
		scanf("%s",str);
		j=strlen(str);
		
		if(str[0]=='-')headb->data=0;
		else headb->data=1;
		
		for(i=1;i<j;i++)
		{
			if(str[i]==';')break;
			t=0;
			while(str[i]!=',')
			{
				t+=10*t+str[i]-'0';
				i++;
			}
			if(lb->data==0)t=-t;
			if(ListInsert(headb, 0, t)==0)
			{
				printf("error!");
				return ;
			}
		}
		
		p=headc->next;
		while(p!=hedac)
		{
			printf("%d",p->data;)
		}
		printf("\n");
		ListDestory(&heada);
		ListDestory(&headb);
		ListDestory(&headc);
}

void add(DLNode *la, DLNode *lb, DLNode *lc)
{
	DLNode *p, *q, *s;
	int t,len;

	p=la->prior;
	q=lb->prior;
		
	while(p!=la && q!=lb)
	{
		t=p->data+q->data;
		if(ListInsert(headc, 0, t)==0)
		{
			printf("error!");
			return ;
		}
		p=p->prior;
		q=q->prior;
	}
	if(p!=la)
	{
		while(p!=la)
		{
			t=p->data;
			if(ListInsert(headc, 0, t)==0)
			{
				printf("error!");
				return ;
			}
			p=p->prior;
		}
	}
	if(q!=lb)
	{
		while(q!=lb)
		{
			t=q->data;
			{
				t=q->data;
				if(ListInsert(headc, 0, t)==0)
				{
					printf("error!");
					return ;
				}
			}
			q=q->prior;
		}
	}

	s=lc->prior;
	while(s!=lc)
	{
		if(s->data>9999)
		{
			s->data-=9999;
			if(s->prior->data++;
		}
		else if(s->data<0)
		{
			s->data+=9999;
			s->prior->data--;
		}
		s=s->prior;
	}
}




	
	
	






⌨️ 快捷键说明

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