#include <iostream.h>
#include <string.h>
int date[4];
int s[24]={
1234,1243,1324,1342,1432,1423,
2134,2143,2314,2341,2431,2413,
3214,3241,3124,3142,3412,3421,
4231,4213,4321,4312,4132,4123};
int comp(int a,int b,int c,int d)
{
int i,sum=0;
for(i=0;i<4;i++)
{
if(date[i]==a)
sum++;
if(date[i]==b)
sum++;
if(date[i]==c)
sum++;
if(date[i]==d)
sum++;
}
cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl<<sum<<endl;
return sum;
}
int main()
{
int i,j;
int guess[10];
int num[10];
int total=0;
int mydate[4];
int x1,x2,x3,x4;
for(i=0;i<4;i++)
cin>>date[i];
for(i=0;i<10;i++)
num[i]=0;
for(i=0;i<10;i++)
guess[i]=i;
if(comp(guess[0],guess[1],guess[2],guess[3])==0)
{
num[0]=-1;
num[1]=-1;
num[2]=-1;
num[3]=-1;
if(comp(guess[0],guess[1],guess[2],guess[4])==0)
{
num[4]=-1;
}
else
{
num[4]=1;
total++;
}
}
else if(comp(guess[0],guess[1],guess[2],guess[3])==4)
{
num[0]=1;
num[1]=1;
num[2]=1;
num[3]=1;
total+=4;
return 0;
}
else
{
if(
comp(guess[4],guess[1],guess[2],guess[3])
+comp(guess[0],guess[4],guess[2],guess[3])
+comp(guess[0],guess[1],guess[4],guess[3])
+comp(guess[0],guess[1],guess[2],guess[4])
>
4*comp(guess[0],guess[1],guess[2],guess[3])
)
{
num[4]=1;
total+=1;
if(
comp(guess[0],guess[1],guess[2],guess[3])
==
comp(guess[4],guess[1],guess[2],guess[3])
)
{
num[0]=1;
total++;
}
else
num[0]=-1;
if(
comp(guess[0],guess[1],guess[2],guess[3])
==
comp(guess[0],guess[4],guess[2],guess[3])
)
{
num[1]=1;
total++;
}
else
num[1]=-1;
if(
comp(guess[0],guess[1],guess[2],guess[3])
==
comp(guess[0],guess[1],guess[4],guess[3])
)
{
num[2]=1;
total++;
}
else
num[2]=-1;
if(
comp(guess[0],guess[1],guess[2],guess[3])
==
comp(guess[0],guess[1],guess[2],guess[4])
)
{
num[3]=1;
total++;
}
else
num[3]=-1;
}
else
{
num[4]=-1;
if(
comp(guess[0],guess[1],guess[2],guess[3])
>
comp(guess[4],guess[1],guess[2],guess[3])
)
{
num[0]=1;
total++;
}
else
num[0]=-1;
if(
comp(guess[0],guess[1],guess[2],guess[3])
>
comp(guess[0],guess[4],guess[2],guess[3])
)
{
num[1]=1;
total++;
}
else
num[1]=-1;
if(
comp(guess[0],guess[1],guess[2],guess[3])
>
comp(guess[0],guess[1],guess[4],guess[3])
)
{
num[2]=1;
total++;
}
else
num[2]=-1;
if(
comp(guess[0],guess[1],guess[2],guess[3])
>
comp(guess[0],guess[1],guess[2],guess[4])
)
{
num[3]=1;
total++;
}
else
num[3]=-1;
}
}
//cout<<total<<"~~~~"<<endl;
if(comp(guess[5],guess[6],guess[7],guess[8])==0)
{
num[5]=-1;
num[6]=-1;
num[7]=-1;
num[8]=-1;
if(comp(guess[5],guess[6],guess[7],guess[8])==0)
{
num[9]=-1;
}
else
{
num[9]=1;
total++;
}
}
else if(comp(guess[5],guess[6],guess[7],guess[8])==4)
{
num[5]=1;
num[6]=1;
num[7]=1;
num[8]=1;
total+=4;
return 0;
}
else
{
if(
comp(guess[9],guess[6],guess[7],guess[8])
+comp(guess[5],guess[9],guess[7],guess[8])
+comp(guess[5],guess[6],guess[9],guess[8])
+comp(guess[5],guess[6],guess[7],guess[9])
>
4*comp(guess[5],guess[6],guess[7],guess[8])
)
{
num[9]=1;
total+=1;
if(
comp(guess[5],guess[6],guess[7],guess[8])
==
comp(guess[9],guess[6],guess[7],guess[8])
)
{
num[5]=1;
total++;
}
else
num[5]=-1;
if(
comp(guess[5],guess[6],guess[7],guess[8])
==
comp(guess[5],guess[9],guess[7],guess[8])
)
{
num[6]=1;
total++;
}
else
num[6]=-1;
if(
comp(guess[5],guess[6],guess[7],guess[8])
==
comp(guess[5],guess[6],guess[9],guess[8])
)
{
num[7]=1;
total++;
}
else
num[7]=-1;
if(
comp(guess[5],guess[6],guess[7],guess[8])
==
comp(guess[5],guess[6],guess[7],guess[9])
)
{
num[8]=1;
total++;
}
else
num[8]=-1;
}
else
{
num[9]=-1;
if(
comp(guess[5],guess[6],guess[7],guess[8])
>
comp(guess[9],guess[6],guess[7],guess[8])
)
{
num[5]=1;
total++;
}
else
num[5]=-1;
if(
comp(guess[5],guess[6],guess[7],guess[8])
>
comp(guess[5],guess[9],guess[7],guess[8])
)
{
num[6]=1;
total++;
}
else
num[6]=-1;
if(
comp(guess[5],guess[6],guess[7],guess[8])
>
comp(guess[5],guess[6],guess[9],guess[8])
)
{
num[7]=1;
total++;
}
else
num[7]=-1;
if(
comp(guess[5],guess[6],guess[7],guess[8])
>
comp(guess[5],guess[6],guess[7],guess[9])
)
{
num[8]=1;
total++;
}
else
num[8]=-1;
}
}
j=0;
for(i=0;i<10;i++)
if(num[i]==1)
{
mydate[j]=i;
j++;
}
i=0;
while(1)
{
x1=s[i]/1000-1;
x2=s[i]/100%10-1;
x3=s[i]/10%10-1;
x4=s[i]%10-1;
cout<<mydate[x1]<<" "<<mydate[x2]<<" "
<<mydate[x3]<<" "<<mydate[x4]<<endl;
if(mydate[x1]==date[0]
&& mydate[x2]==date[1]
&& mydate[x3]==date[2]
&& mydate[x4]==date[3])
return 0;
i+=1;
}
}
评论