问题描述
用1,2,3...9组成3个三位数abc,def和ghi,每个数字恰好使用一次,要求abc:def:ghi=1:2:3。输出所以解,希望吓哥们能尽快给出解答
解决方案
解决方案二:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Collections;publicpartialclassCSDN:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){//Response.Write(IsOneTwoThree(1,2,3));OutputResult();}}publicvoidOutputResult(){ArrayListal=newArrayList(){1,2,3,4,5,6,7,8,9};ArrayListal1=newArrayList();ArrayListal2=newArrayList();ArrayListal3=newArrayList();ArrayListal4=newArrayList();ArrayListal5=newArrayList();ArrayListal6=newArrayList();ArrayListal7=newArrayList();ArrayListal8=newArrayList();intcount=0;for(inti1=1;i1<=9;i1++){al1=newArrayList(al.Count){al[0],al[1],al[2],al[3],al[4],al[5],al[6],al[7],al[8]};al1.RemoveAt(al1.IndexOf(al1[i1-1]));for(inti2=1;i2<=8;i2++){al2=newArrayList(al1.Count){al1[0],al1[1],al1[2],al1[3],al1[4],al1[5],al1[6],al1[7]};al2.RemoveAt(al2.IndexOf(al2[i2-1]));for(inti3=1;i3<=7;i3++){al3=newArrayList(al2.Count){al2[0],al2[1],al2[2],al2[3],al2[4],al2[5],al2[6]};al3.RemoveAt(al3.IndexOf(al3[i3-1]));for(inti4=1;i4<=6;i4++){al4=newArrayList(al3.Count){al3[0],al3[1],al3[2],al3[3],al3[4],al3[5]};al4.RemoveAt(al4.IndexOf(al4[i4-1]));for(inti5=1;i5<=5;i5++){al5=newArrayList(al4.Count){al4[0],al4[1],al4[2],al4[3],al4[4]};al5.RemoveAt(al5.IndexOf(al5[i5-1]));for(inti6=1;i6<=4;i6++){al6=newArrayList(al5.Count){al5[0],al5[1],al5[2],al5[3]};al6.RemoveAt(al6.IndexOf(al6[i6-1]));for(inti7=1;i7<=3;i7++){al7=newArrayList(al6.Count){al6[0],al6[1],al6[2]};al7.RemoveAt(al7.IndexOf(al7[i7-1]));count+=1;//Response.Write(string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}当前第{9}个",al[i1-1],al1[i2-1],al2[i3-1],al3[i4-1],al4[i5-1],al5[i6-1],al6[i7-1],al7[0],al7[1],count)+"</br>");longs=long.Parse(""+al[i1-1]+al1[i2-1]+al2[i3-1]+al3[i4-1]+al4[i5-1]+al5[i6-1]+al6[i7-1]+al7[0]+al7[1]);longa=s/100000;longb=(s-a*100000)/100;longc=s-a*100000-b*100;if(IsOneTwoThree(a,b,c)){Response.Write(string.Format("{0}:{1}:{2}",a,b,c));Response.Write("</br>");}count+=1;//Response.Write(string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}当前第{9}个",al[i1-1],al1[i2-1],al2[i3-1],al3[i4-1],al4[i5-1],al5[i6-1],al6[i7-1],al7[1],al7[0],count)+"</br>");longs1=long.Parse(""+al[i1-1]+al1[i2-1]+al2[i3-1]+al3[i4-1]+al4[i5-1]+al5[i6-1]+al6[i7-1]+al7[1]+al7[0]);longa1=s/10000;longb1=(s-a*100000)/100;longc1=s-a*100000-b*100;if(IsOneTwoThree(a1,b1,c1)){Response.Write(string.Format("{0}:{1}:{2}",a1,b1,c1));Response.Write("</br>");}}}}}}}}Response.Write(""+count);}publicboolIsOneTwoThree(longa,longb,longc){boolflag=false;if((b/a)==2&&(c/a)==3&&(a/b)==2/3){flag=true;}returnflag;}}
貌似还有点小问题,等回家明天再改改看