本文主要是介绍C语言求解刑侦推理题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
C语言暴力求解刑侦推理题
废话不多说,直接上代码
#include <stdio.h>
#include <math.h>int a[1048576][10];
int i,j;
int bool[1048576]={0};
int a0=0;
int a1=0;
int a2=0;
int a3=0;
int amin=0;
int amax=0;int main()
{for(i=0;i<1048576;i++){for(j=0;j<10;j++){a[i][j]=(i%(int)pow(4,10-j))/pow(4,9-j);}}for(i=0;i<1048576;i++){a0=0;a1=0;a2=0;a3=0;amin=0;amax=0;//第二题 if(a[i][1]!=(a[i][4]+2)%4)bool[i]++;//第三题 if(a[i][2]==0){if((a[i][2]==a[i][5])||(a[i][2]==a[i][1])||a[i][2]==a[i][3])bool[i]++;}if(a[i][2]==1){if((a[i][5]==a[i][2])||(a[i][5]==a[i][1])||a[i][5]==a[i][3])bool[i]++;}if(a[i][2]==2){if((a[i][1]==a[i][5])||(a[i][1]==a[i][2])||a[i][1]==a[i][3])bool[i]++;}if(a[i][2]==3){if((a[i][3]==a[i][5])||(a[i][3]==a[i][1])||a[i][3]==a[i][2])bool[i]++;}//第四题if(a[i][3]==0){if(a[i][0]!=a[i][4])bool[i]++;} if(a[i][3]==1){if(a[i][1]!=a[i][6])bool[i]++;} if(a[i][3]==2){if(a[i][0]!=a[i][8])bool[i]++;} if(a[i][3]==3){if(a[i][5]!=a[i][9])bool[i]++;} //第五题if(a[i][4]==0)if(a[i][4]!=a[i][7])bool[i]++;if(a[i][4]==1)if(a[i][4]!=a[i][3])bool[i]++;if(a[i][4]==2)if(a[i][4]!=a[i][8])bool[i]++;if(a[i][4]==3)if(a[i][4]!=a[i][6])bool[i]++;//第六题if(a[i][5]==0){if(a[i][1]!=a[i][7]||a[i][3]!=a[i][7])bool[i]++;} if(a[i][5]==1){if(a[i][0]!=a[i][7]||a[i][5]!=a[i][7])bool[i]++;} if(a[i][5]==2){if(a[i][2]!=a[i][7]||a[i][9]!=a[i][7])bool[i]++;} if(a[i][5]==3){if(a[i][4]!=a[i][7]||a[i][8]!=a[i][7])bool[i]++;} //第七题for(j=0;j<10;j++){if(a[i][j]==0)a0++;if(a[i][j]==1)a1++;if(a[i][j]==2)a2++;if(a[i][j]==3)a3++;}amin=a0;if(amin>a1)amin=a1;if(amin>a2)amin=a2;if(amin>a3)amin=a3;if(a[i][6]==0)if(amin!=a2)bool[i]++;if(a[i][6]==1)if(amin!=a1)bool[i]++;if(a[i][6]==2)if(amin!=a0)bool[i]++;if(a[i][6]==3)if(amin!=a3)bool[i]++;//第八题if(a[i][7]==0){if(abs(a[i][6]-a[i][0])==1)bool[i]++;} if(a[i][7]==1){if(abs(a[i][4]-a[i][0])==1)bool[i]++;} if(a[i][7]==2){if(abs(a[i][1]-a[i][0])==1)bool[i]++;} if(a[i][7]==3){if(abs(a[i][9]-a[i][0])==1)bool[i]++;} //第九题if(a[i][8]==0)if((a[i][0]==a[i][5])==(a[i][5]==a[i][4]))bool[i]++;if(a[i][8]==1)if((a[i][0]==a[i][5])==(a[i][9]==a[i][4]))bool[i]++;if(a[i][8]==2)if((a[i][0]==a[i][5])==(a[i][1]==a[i][4]))bool[i]++;if(a[i][8]==3)if((a[i][0]==a[i][5])==(a[i][8]==a[i][4]))bool[i]++;//第十题 if(a0>amax)amax=a0;if(a1>amax)amax=a1;if(a2>amax)amax=a2;if(a3>amax)amax=a3;if(a[i][9]==0)if((amax-amin)!=3)bool[i]++;if(a[i][9]==1)if(amax-amin!=2)bool[i]++;if(a[i][9]==2)if(amax-amin!=4)bool[i]++;if(a[i][9]==3)if(amax-amin!=1)bool[i]++;}for(i=0;i<1048576;i++){if(bool[i]==0){for(j=0;j<10;j++)printf("%c,",65+a[i][j]);printf("\n");}}return 0;
}
这里是答案
这篇关于C语言求解刑侦推理题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!