标题:六角填数
如图【1.png】所示六角形中,填入1~12的数字。
使得每条直线上的数字之和都相同。
图中,已经替你填好了3个数字,请你计算星号位置所代表的数字是多少?
如图【1.png】所示六角形中,填入1~12的数字。
使得每条直线上的数字之和都相同。
图中,已经替你填好了3个数字,请你计算星号位置所代表的数字是多少?
请通过浏览器提交答案,不要填写多余的内容。
//*********************六角填数
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
int a,b,c,d,e,f,g,h,n;
int flag=0;
int x[6];
for(a=1;a<=12&&flag==0;a++)
for(b=1;b<=12&&flag==0;b++)
for(c=1;c<=12&&flag==0;c++)
for(d=1;d<=12&&flag==0;d++)
for(e=1;e<=12&&flag==0;e++)
for(f=1;f<=12&&flag==0;f++)
for(g=1;g<=12&&flag==0;g++)
for(h=1;h<=12&&flag==0;h++)
for(n=1;n<=12&&flag==0;n++)
{
x[0]=8+a+b+c;x[1]=1+a+n+e;x[2]=1+b+d+h;
x[3]=8+n+f+3;x[4]=c+d+g+3;x[5]=e+f+g+h;
if(x[0]==x[1]&&x[0]==x[2]&&x[0]==x[3]&&x[0]==x[4]&&x[0]==x[5]&&x[1]==x[2]&&x[1]==x[3]&&x[1]==x[4]&&x[1]==x[5]
&&x[2]==x[3]&&x[2]==x[4]&&x[2]==x[5]&&x[3]==x[4]&&x[3]==x[5]&&x[4]==x[5])
{
flag=1;break;
}
}
cout << n ;
return 0;
}