有1至9,9个不同的数字,组成三个三位数,要求第二个三位数是第一个三位数的两倍,第三个三位数是第一个三位数的三倍,请列出三个三位数是多少?

/* 穷举第一个三位数的组成(作简单判断<333)
 * 根据第一个三位数计算第二个,第三个(*2,*3)
 * 判断由三个三位数组成的字符必须含有123456789的任一个
 * by lin6234123456<青古>
 */
using System;
using System.Collections.Generic;
using System.Text;

namespace Cons012001
{
    class T1
    {static void Main(string[] args)
        {
            char[] s = "123456789".ToCharArray();
            string s1 = new String(s);
            string s2 = "123";  //第一个三位数的个位数只能是123
            foreach (char c in s2)
            {
                string s3 = s1.Remove(s1.IndexOf(c),1);  //
              //  Console.WriteLine(s3);
                foreach (char c1 in s3)
                {
                    string s4 = s3.Remove(s3.IndexOf(c1),1);
                  //  Console.WriteLine(s4);
                    foreach (char c2 in s3)
                    {
                        int s5 = Convert.ToInt16(new String(c,1)) * 100 + Convert.ToInt16(new String(c1,1)) * 10 + Convert.ToInt16(new String(c2,1)) ;
                     
                        if (s5 > 333)
                            break;
                        else
                        {    int s6 = s5*2;
                          int s7=s5*3;
                          string s8 = s5.ToString() + s6.ToString() + s7.ToString();  //三个三位数组成的字符
                          bool t = true;
                          if (s8.IndexOf('0') != 0)  //三个三位数组成的字符不能含有0
                          {
                              foreach (char c3 in s1)  //s1="123456789"
                              {
                                  if (s8.IndexOf(c3) < 0)
                                  {
                                      t = false;   //三个三位数组成的字符必须含有123456789的任一个
                                      break;
                                  }                          
                              }
                              if (t) Console.WriteLine(s5.ToString() +"  "+ s6.ToString() + "  "+s7.ToString());
                          }

                        }

                    }
                }
            }
                   Console.ReadLine();

        }
       
        } 

    }
  

posted on 2007-01-21 10:17  凌新华  阅读(3250)  评论(3编辑  收藏  举报