<fieldset>
<center>
<legend>统计每个元素出现的几率</legend>
01:<input type="text" name="01" size="3" id="01">%<font color="red">||</font>
11:<input type="text" name="11" size="3" id="11">%<font color="red">||</font>
21:<input type="text" name="21" size="3" id="21">%<font color="red">||</font>
31:<input type="text" name="31" size="3" id="31">%<font color="red">||</font>
41:<input type="text" name="41" size="3" id="41">%<font color="red">||</font>
51:<input type="text" name="51" size="3" id="51">%<font color="red">||</font>
61:<input type="text" name="61" size="3" id="61">%<font color="red">||</font>
71:<input type="text" name="71" size="3" id="71">%<font color="red">||</font>
81:<input type="text" name="81" size="3" id="81">%<font color="red">||</font>
91:<input type="text" name="91" size="3" id="91">%<font color="red">||</font>
<br>
02:<input type="text" name="02" size="3" id="02">%<font color="red">||</font>
12:<input type="text" name="12" size="3" id="12">%<font color="red">||</font>
22:<input type="text" name="22" size="3" id="22">%<font color="red">||</font>
32:<input type="text" name="32" size="3" id="32">%<font color="red">||</font>
42:<input type="text" name="42" size="3" id="42">%<font color="red">||</font>
52:<input type="text" name="52" size="3" id="52">%<font color="red">||</font>
62:<input type="text" name="62" size="3" id="62">%<font color="red">||</font>
72:<input type="text" name="72" size="3" id="72">%<font color="red">||</font>
82:<input type="text" name="82" size="3" id="82">%<font color="red">||</font>
92:<input type="text" name="92" size="3" id="92">%<font color="red">||</font>
<br>
03:<input type="text" name="03" size="3" id="03">%<font color="red">||</font>
13:<input type="text" name="13" size="3" id="13">%<font color="red">||</font>
23:<input type="text" name="23" size="3" id="23">%<font color="red">||</font>
33:<input type="text" name="33" size="3" id="33">%<font color="red">||</font>
43:<input type="text" name="43" size="3" id="43">%<font color="red">||</font>
53:<input type="text" name="53" size="3" id="53">%<font color="red">||</font>
63:<input type="text" name="63" size="3" id="63">%<font color="red">||</font>
73:<input type="text" name="73" size="3" id="73">%<font color="red">||</font>
83:<input type="text" name="83" size="3" id="83">%<font color="red">||</font>
93:<input type="text" name="93" size="3" id="93">%<font color="red">||</font>
<br>
04:<input type="text" name="04" size="3" id="04">%<font color="red">||</font>
14:<input type="text" name="14" size="3" id="14">%<font color="red">||</font>
24:<input type="text" name="24" size="3" id="24">%<font color="red">||</font>
34:<input type="text" name="34" size="3" id="34">%<font color="red">||</font>
44:<input type="text" name="44" size="3" id="44">%<font color="red">||</font>
54:<input type="text" name="54" size="3" id="54">%<font color="red">||</font>
64:<input type="text" name="64" size="3" id="64">%<font color="red">||</font>
74:<input type="text" name="74" size="3" id="74">%<font color="red">||</font>
84:<input type="text" name="84" size="3" id="84">%<font color="red">||</font>
94:<input type="text" name="94" size="3" id="94">%<font color="red">||</font>
<br>
05:<input type="text" name="05" size="3" id="05">%<font color="red">||</font>
15:<input type="text" name="15" size="3" id="15">%<font color="red">||</font>
25:<input type="text" name="25" size="3" id="25">%<font color="red">||</font>
35:<input type="text" name="35" size="3" id="35">%<font color="red">||</font>
45:<input type="text" name="45" size="3" id="45">%<font color="red">||</font>
55:<input type="text" name="55" size="3" id="55">%<font color="red">||</font>
65:<input type="text" name="65" size="3" id="65">%<font color="red">||</font>
75:<input type="text" name="75" size="3" id="75">%<font color="red">||</font>
85:<input type="text" name="85" size="3" id="85">%<font color="red">||</font>
95:<input type="text" name="95" size="3" id="95">%<font color="red">||</font>
<br>
06:<input type="text" name="06" size="3" id="06">%<font color="red">||</font>
16:<input type="text" name="16" size="3" id="16">%<font color="red">||</font>
26:<input type="text" name="26" size="3" id="26">%<font color="red">||</font>
36:<input type="text" name="36" size="3" id="36">%<font color="red">||</font>
46:<input type="text" name="46" size="3" id="46">%<font color="red">||</font>
56:<input type="text" name="56" size="3" id="56">%<font color="red">||</font>
66:<input type="text" name="66" size="3" id="66">%<font color="red">||</font>
76:<input type="text" name="76" size="3" id="76">%<font color="red">||</font>
86:<input type="text" name="86" size="3" id="86">%<font color="red">||</font>
96:<input type="text" name="96" size="3" id="96">%<font color="red">||</font>
<br>
07:<input type="text" name="07" size="3" id="07">%<font color="red">||</font>
17:<input type="text" name="17" size="3" id="17">%<font color="red">||</font>
27:<input type="text" name="27" size="3" id="27">%<font color="red">||</font>
37:<input type="text" name="37" size="3" id="37">%<font color="red">||</font>
47:<input type="text" name="47" size="3" id="47">%<font color="red">||</font>
57:<input type="text" name="57" size="3" id="57">%<font color="red">||</font>
67:<input type="text" name="67" size="3" id="67">%<font color="red">||</font>
77:<input type="text" name="77" size="3" id="77">%<font color="red">||</font>
87:<input type="text" name="87" size="3" id="87">%<font color="red">||</font>
97:<input type="text" name="97" size="3" id="97">%<font color="red">||</font>
<br>
08:<input type="text" name="08" size="3" id="08">%<font color="red">||</font>
18:<input type="text" name="18" size="3" id="18">%<font color="red">||</font>
28:<input type="text" name="28" size="3" id="28">%<font color="red">||</font>
38:<input type="text" name="38" size="3" id="38">%<font color="red">||</font>
48:<input type="text" name="48" size="3" id="48">%<font color="red">||</font>
58:<input type="text" name="58" size="3" id="58">%<font color="red">||</font>
68:<input type="text" name="68" size="3" id="68">%<font color="red">||</font>
78:<input type="text" name="78" size="3" id="78">%<font color="red">||</font>
88:<input type="text" name="88" size="3" id="88">%<font color="red">||</font>
98:<input type="text" name="98" size="3" id="98">%<font color="red">||</font>
<br>
09:<input type="text" name="09" size="3" id="09">%<font color="red">||</font>
19:<input type="text" name="19" size="3" id="19">%<font color="red">||</font>
29:<input type="text" name="29" size="3" id="29">%<font color="red">||</font>
39:<input type="text" name="39" size="3" id="39">%<font color="red">||</font>
49:<input type="text" name="49" size="3" id="49">%<font color="red">||</font>
59:<input type="text" name="59" size="3" id="59">%<font color="red">||</font>
69:<input type="text" name="69" size="3" id="69">%<font color="red">||</font>
79:<input type="text" name="79" size="3" id="79">%<font color="red">||</font>
89:<input type="text" name="89" size="3" id="89">%<font color="red">||</font>
99:<input type="text" name="99" size="3" id="99">%<font color="red">||</font>
<br>
</fieldset>
</center>
</body>
</html>

解决方案 »

  1.   

    对于应届毕业生来说,确实有点麻烦。
    对于有Javascript开发经验的人,是很easy的。如果叫我做,预计时间是40至90分钟。
      

  2.   

    看人挑担不吃力!都说很容易,不妨做做看。面试时遇到这样的题,也只有“投降”了写了点(近3小时),大家看看。对了,还有第8、11没有做<script>
    //检查值是否在数组中
    function in_array(value, array) {
      for(var i=0; i<array.length; i++)
        if(value == array[i]) return true;
      return false;
    }//把字符串按2个字符一组切割成数组
    function slice(s) {
      var ar = new Array();
      for(var i=0; i<s.length; i+=2)
        ar.push(s.substr(i, 2));
      return ar;
    }//提取随机数列表
    function get_random_list() {
      var i;
      var list = document.getElementById("list");
      random_list = new Array();
      for(i=0; i<list.length; i++)
        random_list[i] = list.options[i].text;
      random_sub_list = new Array();
      for(i=0; i<random_list.length; i++) {
        random_sub_list[i] = slice(random_list[i]);
      }
    }//生成新随机数
    function creat_n() {
      //设定的生成数长度
      nlength = document.getElementById("Nlength").value;
      if(nlength == '') {
        alert('必须有生成数长度');
        document.getElementById("Nlength").focus();
        return false;
      }
      if(nlength % 2 != 0) {
        alert('生成数长度必须是偶数');
        document.getElementById("Nlength").focus();
        return false;
      }  //设定的生成数的最大元素
      nmax = document.getElementById("Nmax").value;
      if(nmax == '') {
        alert('必须有生成数的最大元素');
        document.getElementById("Nmax").focus();
        return false;
      }  //设定的生成数的某3个元素
      na = document.getElementById("Na").value;
      if(na != '' && na < '01') {
        alert('不能为空');
        document.getElementById("Na").focus();
        return false;
      }
      nb = document.getElementById("Nb").value;
      if(nb != '' && nb < '01') {
        alert('不能为空');
        document.getElementById("Nb").focus();
        return false;
      }
      nc = document.getElementById("Nc").value;
      if(nc != '' && nc < '01') {
        alert('不能为空');
        document.getElementById("Nc").focus();
        return false;
      }  //提取随机数列表备用
      get_random_list();  //开始生成随机数
      var i, t, ar, p;
      var err = 0;
      while(1) {
        ar =new Array();
        p = 0;
        if(na != '') {
          ar.push(na);
          p++;
        }
        if(nb != '') {
          ar.push(nb);
          p++;
        }
        if(nc != '') {
          ar.push(nc);
          p++;
        }
        len = nlength/2 - p;
        for(i=0; i<len; i++) {
          do {
            t = parseInt(Math.random()*nmax)+1;
            if(t < 10)
              t = '0'+t;
          }while(in_array(t, ar));    
          ar.push(t);
        }
        ar.sort();
        n = ar.join('');
        t = random_list[random_list.length-1];
        if(! in_array(n, random_list) && n.substr(0, 6) != t.substr(0, 6))
          break;
        if(err++ > 100) {
          alert('计算超时');
          return;
        }
      }
      document.getElementById("N").value = n;
    }
    </script>
      

  3.   

    我大体用时02:57:00
    少两问每做,若比我稍熟练点,写完应该没问题!
    况且还有1小时调试时间呢?我已答部分已经调试过,没有问题的剩余的第8问
    把结果加入到列表中只是一两句而已第11问
    是遍历random_sub_list数组计数、求百分比、赋值
    并无多大难度
      

  4.   

    8--11没做
    一个小时(注:抽牌算法是以前收集整理的)<script language=javascript>
    //得到m张牌里的n张牌 ( m>=n>0) 部分代码来自:http://community.csdn.net/Expert/topic/3858/3858964.xml?temp=.5909693fason的回贴。
    function getRandomArray(m,n)   
    {
    var array1=new Array(m);
    for(var i=0;i<m;i++)
    array1[i]=i;
    var m2=m-0.00001;
    for(var i=0;i<n;i++)
    {
    var rnd=Math.floor(Math.random()*m2);
    var swap=array1[i];array1[i]=array1[rnd];array1[rnd]=swap;
    }
    return(array1.slice(0,n));
    }
    function checkNewNumberIsOk(tempArray)
    {
    return true;}function creat_n()
    {
    document.all.newram.value=get_n();}function get_n()
    {
    if(!confirm("continue?")) return false;
    var NlengthValue=document.all.Nlength.value;
    var NmaxValue=document.all.Nmax.value;
    var abcArray=new Array();
    abcArray[0]=document.getElementById("Na").value;
    abcArray[1]=document.getElementById("Nb").value;
    abcArray[2]=document.getElementById("Nc").value;
    var tempArray=getRandomArray(NmaxValue,NlengthValue/2-3); for(var i=2;i>-1;i--)
    {
    var needAdd=true;
    for(var j=0;j<tempArray.length;j++)
    {
    if(abcArray[i]==tempArray[j])
    {
    return get_n();
    }
    }
    tempArray[tempArray.length]=abcArray[i];
    }
    return tempArray.sort(compareFun);}
    function compareFun(a,b)
    {
    return a-b;
    }</script>
      

  5.   

    经管这个题目不适合做“面试”,但还是一个很好的题目。有时间做做还是很好的!
    以下解答接在上面的解答之后
    08.新生成的随机数N自动加入为“随机数列表”的最后一个随机数
      var list = document.getElementById("list");
      list.options[list.options.length] = new Option(n);11.统计列表中每个元素出现的几率
      //重新提取随机数列表
      get_random_list();
      //为简化书写建立到显示区域的联系并初始化显示区域
      ar = new Array();
      for(i=1; i<100; i++) {
        id = i;
        if(i < 10) id = '0'+i;
        ar[id] = document.getElementById(id);
        ar[id].value = '';
      }
      //统计
      var cnt = 0;
      for(i=0; i<random_sub_list.length; i++) {
        t = random_sub_list[i];
        for(j=0; j<t.length; j++) {
          cnt++;
          ar[t[j]].value++;
        }
      }
      //计算百分比
      for(i in ar)
        if(ar[i].value != '')
          ar[i].value = (ar[i].value/cnt*100).toFixed(2);
    }
    ********注意,这个题目有错误:
    显示统计值的文本框缺少编号为00、10、20、30、40、50、60、70、80、90的对象
    而“随机数列表”中存在
    0318192021 的20
    0616172021 的20
    0102081015 的10
    虽然有可能不准出现00(题中未说明)
    但是不允许个位为0是必须声明的!因为这涉及到随机树产生的算法
      

  6.   

    感觉是个不错的题目
    考的东西比较全面
    基本功,编程经验,个人思维能力,代码质量,工作效率,debug效率。。等等
    都可以得到很好的体现不足之处是:
    对于是知道洗牌、抽牌算法的人来说,实在是捡了太大的便宜。
    光这个算法,如果自己写,
    花的时间多少是个问题,
    代码质量上有很大的弹性空间
      

  7.   

    xuzuning(唠叨) 的代码里这一句有可能产生一个比nmax还大1的数,尽管可能性比较小
    t = parseInt(Math.random()*nmax)+1;
      

  8.   

    Math.random( )说明
    产生的伪随机数介于 0 和 1 之间(含 0,不含 1),也就是,返回值可能为0,但总是小于1。在第一次加载 JScript 时随机数发生器自动产生 。
    *****
    alert(parseInt(0.9999)); //out 0
      

  9.   

    我的参考书(是jscript,没有查javascript的参考书)上这么说:描述
    返回介于 0 和 1 之间的伪随机数。
    语法
    Math.random( ) 
    说明
    产生的伪随机数介于 0 和 1 之间(含 0 和 1)。在第一次加载 JScript 时随机数发生器自动产生 。
      

  10.   

    也有可能只小于0
    参考书是在本机:C:\Program Files\Microsoft Visual Studio\Common\IDE\IDE98\MSE\2052\JSCRIPT5.CHM
    害我以前还总要去考虑这种情况:查了一下java.lang.Math.random():
              Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
      

  11.   

    看到xuzuning(唠叨)更新的题解,真要叹服了:迅速好快啊……