js-尋找特徵數

來源:互聯網
上載者:User

標籤:

輸入要尋找的數字範圍、特徵數以及出現頻率,點擊尋找

 

↓↓↓↓↓↓↓代碼↓↓↓↓↓↓↓↓↓↓↓↓↓↓

 

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>尋找特徵數</title>    <link rel="stylesheet" href="style.css" type="text/css"></head><body><div id=‘bor‘ ><fieldset>    <label for="start">開始範圍</label>    <input id=‘start‘ type="text" placeholder="請輸入數字">    <label for="end">結束範圍</label>    <input type="text" id="end" placeholder="請輸入數字">    <label for="num">特徵數字</label>    <input type="text" id="num" placeholder="請輸入數字">    <label for="pinlv">出現頻率</label>    <input type="text" id="pinlv" placeholder="請輸入數字">    <input type="button" id="btn1" value="方法一尋找">    <input type="button" id="btn2" value="方法二尋找"></fieldset><br><div id=‘result‘ style="overflow:auto"></div> </div>    </body></html>
<script>    window.onload=function(){        document.getElementById(‘btn1‘).onclick=function(){            document.getElementById("result").innerHTML="方法 一 結果:";            var start=document.getElementById(‘start‘).value;            var end=document.getElementById(‘end‘).value;            var num=document.getElementById(‘num‘).value;            var pinlv=document.getElementById(‘pinlv‘).value;            var count=0;            var narry=new Array();            for(var i=start;i<=end;i++){                count=0;                count+=parseInt(i.toString().split(num).length-1)//計算特徵數字出現的頻率                if(count>=pinlv){//當特徵數字出現的頻率大於等於規定的頻率,將數字推進數組當中                    narry.push(i)                }            }            for(var j=0;j<narry.length;j++){                if(j==narry.length-1){                    document.getElementById("result").innerHTML+=narry[j];                    break;                }//當輸出到最後一個數字時不需要逗號                document.getElementById("result").innerHTML+=narry[j];//按順序輸出數組                document.getElementById("result").innerHTML+=",";                if((j+1)%5==0){                    document.getElementById("result").innerHTML+=‘<br>‘;//每隔五個數字換行                }            }        }        document.getElementById(‘btn2‘).onclick=function(){            document.getElementById("result").innerHTML="方法 二 結果:";            var start=document.getElementById(‘start‘).value;            var end=document.getElementById(‘end‘).value;            var num=document.getElementById(‘num‘).value;            var pinlv=document.getElementById(‘pinlv‘).value;            var count=0;            var narry=new Array();            for(var i=start;i<=end;i++){                count=0;                var loc=0;                loc=i.toString().indexOf(num,loc);                                                if(loc!=(-1)){                    count++                    if(loc<i.toString().length-1){//如果indexOf還沒有把全部的字元找一遍就繼續找                        loc=i.toString().indexOf(num,(loc+1))//繼續尋找字串後續的字元有沒有特徵數字                        if(loc<0){//如果後續的字元沒有特徵數字,則計算頻率是否符合我們要的頻率,符合就把數字推進數組裡去                            if(count>=pinlv){//當特徵數字出現的頻率大於等於規定的頻率,將數字推進數組當中                                 narry.push(i)                            }                            continue;                        }else{//如果後續字元有特徵數字則count++,然後繼續尋找                            while(loc!=(-1)){                            count++;                            loc=i.toString().indexOf(num,(loc+1))                        }                        }                                                // if(loc!=(-1)){                        //     count++;                        // }                    }                }                if(count>=pinlv){//當特徵數字出現的頻率大於等於規定的頻率,將數字推進數組當中                     narry.push(i)                }            }                for(var j=0;j<narry.length;j++){                if(j==narry.length-1){                    document.getElementById("result").innerHTML+=narry[j];                    break;                }//當輸出到最後一個數字時不需要逗號                document.getElementById("result").innerHTML+=narry[j];//按順序輸出數組                document.getElementById("result").innerHTML+=",";                if((j+1)%5==0){                    document.getElementById("result").innerHTML+=‘<br>‘;//每隔五個數字換行                }            }    }    }</script>

 

開始範圍 結束範圍 特徵數字 出現頻率
 

js-尋找特徵數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.