û˼·û˼·°¡ ´óÏÀÁô²½£¡
¸øÄã1 2 3 4 5 6 Õâ¸öÁù¸öÊý ÈÃÄã´òÓ¡ËùÓÐ×éºÏµÄ½á¹û 4²»ÄÜÅÅÔÚµÚÈýλ 3ºÍ5²»ÄÜÏàÁÚ
[½â¾ö°ì·¨]
Õâ²»ÊÇÆÕ±éµÄÅÅÁÐ×éºÏÌâô£¿²»ÓóÌÐò×Ô¼º¶¼ÄÜËã³öÀ´ÁË
[½â¾ö°ì·¨]
ÉÙÄ꣬£¬µÈ»á£¬£¬¸çÏÖÔÚȥд¡£¡£
[½â¾ö°ì·¨]
·´¹ýÀ´ÏëÏëºÃÏñ²»´í¡£
[½â¾ö°ì·¨]
ÕâÎÊÌâÇ°¼¸ÖÜÓÐÈ˾ͷ¢¹ýÁË£¬ºÃÏñ½ÐʲôÃæÊÔÌâÖ®ÀàµÄ£¬×Ô¼ºÕÒÕÒ°É¡£
Ò»µã˼·£ºµÝ¹é¡£
[½â¾ö°ì·¨]
°Ù¶ÈÁËһϣ¬Ñ§Ï°Ò»Ï£¡
package testWork;
/**
*
* ÓÃ1¡¢2¡¢2¡¢3¡¢4¡¢5ÕâÁù¸öÊý×Ö£¬ÓÃjavaдһ¸ö³ÌÐò£¬´òÓ¡³öËùÓв»Í¬µÄÅÅÁÐ
* È磺512234¡¢412345µÈ£¬ÒªÇó£º"4"²»ÄÜÔÚµÚÈý룬"3"Óë"5"²»ÄÜÏàÁ¬¡£
*
* @author user
* @version [°æ±¾ºÅ, Jun 29, 2011]
* @see [Ïà¹ØÀà/·½·¨]
* @since [²úÆ·/Ä£¿é°æ±¾]
*/
public class Test1
{
private int[] numbers = new int[] {1, 2, 3, 3, 4, 5};
public int n;
private String lastResult = "";
private boolean validate(String s)
{
if (s.compareTo(lastResult) <= 0) //°´×Öµä˳Ðò±È½ÏÁ½¸ö×Ö·û´®¡£
{
return false;
}
if (s.charAt(2) == '4')//"4"²»ÄÜÔÚµÚÈýλ
{
return false;
}
if (s.indexOf("35") >= 0 || s.indexOf("53") >= 0)//"3"Óë"5"²»ÄÜÏàÁ¬
{
return false;
}
return true;
}
/**
* <Ò»¾ä»°¹¦ÄܼòÊö>
* <¹¦ÄÜÏêϸÃèÊö>
* @param index
* @param result [²ÎÊý˵Ã÷]
*
* @return void [·µ»ØÀàÐÍ˵Ã÷]
* @exception throws [Î¥ÀýÀàÐÍ] [Î¥Àý˵Ã÷]
* @see [Àà¡¢Àà#·½·¨¡¢Àà#³ÉÔ±]
*/
public void list(String index, String result)
{
for (int i = 0; i < numbers.length; i++)
{
if (index.indexOf(i+48) < 0)
{
String s = result + String.valueOf(numbers[i]);
if (s.length() == numbers.length)
{
if (validate(s))
{
System.out.println(s);
lastResult = s;
n++;
}
break;
}
list(index + String.valueOf(i), s);
}
}
}
/**
* Ö÷³ÌÐòÈë¿Ú
* <¹¦ÄÜÏêϸÃèÊö>
* @param args [²ÎÊý˵Ã÷]
*
* @return void [·µ»ØÀàÐÍ˵Ã÷]
* @exception throws [Î¥ÀýÀàÐÍ] [Î¥Àý˵Ã÷]
* @see [Àà¡¢Àà#·½·¨¡¢Àà#³ÉÔ±]
*/
public static void main(String[] args)
{
Test1 t = new Test1();
t.list("", "");
System.out.println("×ÜÊý£º" + t.n);
}
}