***********************************************************
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
FILE *in, *out;
int i, j, k, temp, temp1, temp2, temp3, temp4, a, a1, a2, a3, a4;
int arrayOf4[25] =
{123,134,145,156,167,178,189,1234,1245,1256,1267,1278,1289,
2345,2356,2367,2378,2389,3456,3467,3489,4567,5678,5689,6789};
int inArray[100], matchArray1[10], matchArray2[10], found = 0, possible;
int numCount, score;
/*
** Open
*/
if((in = fopen("drawsP4.txt", "r")) == NULL)
{
printf("could not open drawsP4.txt\n");
getch();
exit(0);
}
if((out = fopen("out.txt", "w")) == NULL)
{
printf("could not open out.txt\n");
getch();
exit(0);
}
/*
** Start scanning
*/
i = 0;
while(!feof(in) && i < 50)
{
fscanf(in, "%d", (inArray + i));
i++;
}
numCount = i;
printf("Pairs to play are:\n");
fprintf(out, "Pairs to play are:\n");
start:
for(i = 0; i < 25; i++)
{
possible = 0;
score = 0;
temp = arrayOf4[i];
temp1 = temp/1000;
temp2 = (temp - 1000*temp1)/100;
temp3 = (temp - 1000*temp1 - 100*temp2)/10;
temp4 = (temp - 1000*temp1 - 100*temp2 - 10*temp3);
j = 0;
for(j = 0; j < numCount; j++)
{
for( k = 0; k < 10; k++)
{
matchArray1[k] = 0;
matchArray2[k] = 0;
}
a = inArray[j];
a1 = a/1000;
a2 = (a - 1000*a1)/100;
a3 = (a - 1000*a1 - 100*a2)/10;
a4 = (a - 1000*a1 - 100*a2 - 10*a3);
matchArray1[temp1] = 1;
matchArray1[temp2] = 1;
matchArray1[temp3] = 1;
matchArray1[temp4] = 1;
matchArray1[a1]++;
matchArray1[a2]++;
matchArray1[a3]++;
matchArray1[a4]++;
score = 0;
for(k = 0; k < 10; k++)
{
if(matchArray1[k] == 2)
{
score = score + 1;
}
}
if(score < 3 )
{
possible++;
}
}
if(possible == numCount)
{
printf("%d%d-", temp1,temp2);
printf("%d%d-", temp1,temp3);
printf("%d%d-", temp1,temp4);
printf("%d%d-", temp2,temp3);
printf("%d%d-", temp2,temp4);
printf("%d%d\n", temp3,temp4);
fprintf(out, "%d%d-%d%d-%d%d-%d%d-%d%d-%d%d\n",
temp1, temp2, temp1, temp3, temp1, temp4,
temp2, temp3, temp2, temp4, temp3, temp4);
found = 1;
}
}
if(found == 0)
{
numCount = numCount - 1;
goto start;
}
printf("Enter any key to continue\n", numCount);
getch();
close(in);
close(out);
}