JavaScript solves Joseph problem _javascript skills

Source: Internet
Author: User
Starting in bbs.huse.cn
The array objects in JavaScript are bundled with powerful methods
So it can implement powerful array operations with very short code.
And these functions to C or C + + implementation may take several times the code
And the readability is even worse.
<ptml> <pead> <title> Joseph JavaScript solution </title> <script language= "JavaScript" >//writ Ten by Lola.huse.2006-4-1 function PrintArray (ARR) {for (Var j=0;j<arr.length;j++) document.write (arr[j]+ ""); document.write ("")} function A (Peopleamount,passkey) {var ar=new Array (); for (Var i=0;i<peopleamount;i++) Ar.push (i+1); document.write ("Originally troops for:") PrintArray (AR); document.write ("keyword is" +passkey+ "-----------") var Currentpos=1; while (ar.length>1) {currentpos= (currentpos+ (passKey-1))%ar.length;//if (currentpos==0) currentpos=ar.length// document.write (currentpos+1+ ""); document.write (Ar.splice (currentpos-1,1) + "number gone, the remaining members are:"); PrintArray (AR); } document.write ("Last remaining is:") PrintArray (AR); document.write ("continue"); } </script> </pead> <body onload= "javascript:document.form1.t1.value="; javascript: Document.form1.t2.value= ' "> <form method=" POST "Name=" Form1 "action=" Javascript:a (parseintRm1. T1.value), parseint (Document.form1.T2.value)) "> <p> number <input type=" text "name=" T1 "> </p> &LT;P&G T Key<input name= "T2" type= "text" id= "T2" > </p> <p> <input type= "Submit" value= "Submit" Name= "B1" on click= "Javascript:return" (document.form1.t1.value!= ' | | document.form1.t2.value!= ') ' > </p> </form> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.