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

📄 class.cpp

📁 设计一个算法
💻 CPP
字号:
#include <iostream.h>
#include<fstream.h>
ifstream in("input.txt");
ofstream out("output.txt");
class List;
class Node 
{
	friend List;
	friend int compare(List a,List b,int & n);
	public:	
		int data;
		Node *next;
};
class List
{
	public:	
        Node *first;
		List(){first=0;}
		List& Insert(int k,int & n);
	friend int compare(List a,List b,int & n);
};
 List& List::Insert(int k,int & n)
{	int l,x,r,s;
   	for(l=0;l<n;l++)
	{
		if(k==0)
		{
			k++;
			in>>r>>s>>x;
		}
  		else 
			in>>x;
		Node *y=new Node;
		y->data=x;
		y->next=first;
		first=y;
	}
	return *this;
}    
int compare(List a,List b,int & n)
{
	int i,justify=1;
	Node *p=a.first,*q=b.first ;
	for(i=0;i<n;i++) 
	{
		if(p->data!=q->data)
		{
			justify=0;
			break;
		}
		p=p->next;
		q=q->next;
	}
	if(justify==1)
		return 1;//相等
	else
		return 0;//不等
}


int main()
{
    int m,n,i,j,k,sum=0;
	ifstream in("input.txt");
    in>>m>>n;
	List *L;
	L=new List[m];
	for(i=0;i<m;i++)			
		L[i].Insert(i,n);
    int *b;
	b=new int[m];
	for(int z=0;z<m;z++)
		b[z]=1;
	for(j=0;j<m;j++)
	{
		if(b[j]!=0)
		{
			for(k=j+1;k<m;k++)
			   if(compare(L[j],L[k],n)==1)
				  b[k]=0;
            sum++;
		}
		 else continue;
       
	}
	ofstream out("output.txt");
	out<<sum;
return 0;
}

⌨️ 快捷键说明

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