|
发表于 2003-7-18 09:55:19
|
显示全部楼层
#include <stdio.h>
int
main()
{
for(int firstNumber = 2;firstNumber < 9;firstNumber ++)
{
int secondNumberStart = 10 / firstNumber;
if (secondNumberStart == 0) secondNumberStart = 1;
for(int secondNumber = secondNumberStart;secondNumber < 9;secondNumber ++)
for(int thirdNumber = 1;thirdNumber < 9;thirdNumber ++)
for(int forthNumber = 1;forthNumber < 9;forthNumber ++)
{
if ((firstNumber == secondNumber) ||
(firstNumber == thirdNumber) ||
(firstNumber == forthNumber) ||
(secondNumber == forthNumber) ||
(secondNumber == thirdNumber) ||
(thirdNumber == forthNumber))
{
}
else
{
int result = firstNumber * (secondNumber * 100 + thirdNumber * 10 + forthNumber);
if (result > 999)
{
int selectedNumber[4] = {firstNumber,secondNumber,thirdNumber,forthNumber};
int resultNumber[4] = {result / 1000,result / 100 % 10,result / 10 % 10,result % 10};
bool found = true;
if ((resultNumber[0] == resultNumber[1]) ||
(resultNumber[0] == resultNumber[2]) ||
(resultNumber[0] == resultNumber[3]) ||
(resultNumber[1] == resultNumber[2]) ||
(resultNumber[1] == resultNumber[3]) ||
(resultNumber[2] == resultNumber[3]))
{
found = false;
}
if (found)
{
for(int i=0;i<4;i++)
{
if ((resultNumber == 0) ||
(resultNumber == 9))
{
found = false;
break;
}
else
{
for(int k=0;k<4;k++)
{
if (resultNumber == selectedNumber[k])
{
found = false;
}
}
}
}
}
if (found)
{
printf("(%d) * (%d)(%d)(%d)=(%d)(%d)(%d)(%d)\n",
firstNumber,secondNumber,thirdNumber,forthNumber,
resultNumber[0],resultNumber[1],resultNumber[2],resultNumber[3]);
}
}
}
}
}
return 0;
}
c的应该和java差不多 |
|