C # implementation: Given a [0-9] array, the minimum value of any number consisting of an array is evaluated

Source: Internet
Author: User

 classProgram {Static voidMain (string[] args) {List<int> c =Newlist<int> () {1,2,3,4,5 };            C.sort (); varresult = GetNumber (c,27423536); Console.WriteLine ("{0}", result);        Console.readkey (); }        Private Static intGetNumber (list<int> C,intk) {c.sort (); intresult =0; intKK =K; List<int> eachnum =Newlist<int>(); //convert each bit of the K to a list.             while(k! =0) {Eachnum.add (k%Ten); K= k/Ten; }            //get the each bit which is larger or equal the same position of K.             for(inti = Eachnum.count-1; I >=0; i--) {result= result *Ten+Getcurrentnum (c, eachnum[i]); }            //If The result by below is small than target. Replace the number from low position.            intj =0;  while(Result <= KK && J <eachnum.count) {J++; if(C.where (item = Item > EACHNUM[J-1]). Count () = =0)                {                    Continue; } result= (Result/(int) Math.pow (Ten, j)) * (int) Math.pow (Ten, J); Result= result + getminvallargerthant (c.where item = item > EACHNUM[J-1]). First (), C.first (), J-1); }            //If The result is a still small than target, carry in adding.            if(Result <=KK) {Result= Getminvallargerthant (C.where (item = Item >0).            First (), C.first (), eachnum.count); }            returnresult; }         Public Static intGetminvallargerthant (intFirstisnotzero,intFirstnum,intlength) {            intresult =Firstisnotzero;  for(inti =0; i < length; i++) {result= result *Ten+Firstnum; }            returnresult; }        //Get for each number min value larger than the same position.         Public Static intGetcurrentnum (list<int> C,inthighnum) {            foreach(intCIteminchc) {if(CItem >=highnum) {                    returnCItem; }            }            return 0; }    }
View Code

C # implementation: Given a [0-9] array, the minimum value of any number consisting of an array is evaluated

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.