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> <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]