#include<stdio.h>
#ifdef _WIN32
	#include<conio.h>
	#include<Windows.h>
#endif


#define domain 10

void readfile(char fn[13],char adjancy[domain+1][domain+1],int nocheck,int n2);

void main()
{
	char adjacencymx[domain+1][domain+1];
	char define1,define2;
	char fn[13] = "pp3-1.dat";
	char fn2[13] = "pp3-2.dat";

	int nocol,nocheck=1,i,j,n1=10,n2=10;

	for(i=1;i<=10;i++)
	{
		for(j=1;j<=10;j++)
		{
			adjacencymx[i][j] = 0;
		}
	}

	readfile(fn,adjacencymx,nocheck,n1);
	printf("}\n\n");

	define1=1;
	
	for(i=1;i<=10;i++)
	{
		define2 = 0;
		nocol = 0;
		
		for(j=1;j<=10;j++)
		{
			if(adjacencymx[i][j] == 1)
			{
				define2 = 1;
				nocol++;
			}
		}
		
		if(define2 == 0)
		{
			define1 = 0;
			printf("%5cf%d is not function because",' ',nocheck);
			printf(" f(%d) is not defined.\n",i);
		}

		if(nocol > 1)
		{
			define1 = 0;
			printf("%5cf%d is not function becuase",' ',nocheck);
			printf(" f(%d) is not unique image.\n",i);
		}
	}

	if(define1 == 1)
	{
		printf("%5cf%d is well-defined.\n\n",' ',nocheck);
	}
	nocheck++;
	printf("\n\n");
	for(i=1;i<=10;i++)
	{
		for(j=1;j<=10;j++)
		{
			adjacencymx[i][j] = 0;
		}
	}

	readfile(fn2,adjacencymx,nocheck,n2);
	printf("}\n\n");

	define1=1;
	
	for(i=1;i<=10;i++)
	{
		define2 = 0;
		nocol = 0;
		
		for(j=1;j<=10;j++)
		{
			if(adjacencymx[i][j] == 1)
			{
				define2 = 1;
				nocol++;
			}
		}
		
		if(define2 == 0)
		{
			define1 = 0;
			printf("%5cf%d is not function because",' ',nocheck);
			printf(" f(%d) is not defined.\n",i);
		}

		if(nocol > 1)
		{
			define1 = 0;
			printf("%5cf%d is not function becuase",' ',nocheck);
			printf(" f(%d) is not unique image.\n",i);
		}
	}

	if(define1 == 1)
	{
		printf("%5cf%d is well-defined.\n\n",' ',nocheck);
	}


	system("PAUSE");
}

void readfile(char fn[13],char adjacency[domain+1][domain+1],int nocheck,int n2)
{
	FILE *fp;
	int i,x,y;

	fp = fopen(fn,"r");
	printf("%5cf%d={",' ',nocheck);

	for(i=1;i<=n2;i++)
	{
		fscanf(fp,"%d %d",&x,&y);
		adjacency[x][y] = 1;
		printf("%2c(%2d,%2d)",' ',x,y);
	}
	fclose(fp);
}