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

📄 class.c

📁 向量分配问题
💻 C
字号:
#include<stdio.h>
#include<malloc.h>

struct A{
	int* a;
	struct A * next;
};
int compare(struct A *t,struct A *p2,int c){
	int i;
	for(i=0;i<c;i++){
		if(t->a[i]!=p2->a[i])return 1;
	}
	return 0;
}
struct A * insert(struct A *p,struct A *p2){
	if(p==NULL){p=p2;p2->next=NULL;}
	else {p2->next=p;p=p2;}
	return p;
}
void mfree(struct A*p){
	struct A*p1,*p2;
	p2=p;
	while(p2->next!=0){
		p1=p2;
		p2=p2->next;
		free(p1->a);
		free(p1);
	}
	free(p2->a);
	free(p2);
}



void main(){
	
	int sum,c,i,i2,result;
	
	
	struct A *p=0,*p2;
	int temp;
	struct A * t;
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d",&sum,&c);
	
	result=0;
	for(i=0;i<sum;i++){
		
		p2=malloc(sizeof*p2);
		p2->a=malloc(c*sizeof(int));
		for(i2=0;i2<c;i2++)
			scanf("%d",p2->a+i2);
		temp=0;t=p;

		while(t!=NULL){
			if(compare(t,p2,c)==0){temp=1;break;}
			t=t->next;
		}
		if(temp==0){p=insert(p,p2);result++;}
		else free(p2);
	}
	printf("%d",result);
	
	
	mfree(p);
}

	




⌨️ 快捷键说明

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