promotion image of download ymail app
Promoted

java script 計算題目

123456789按照順序依序插入+-符號

解要等於100

求java script語法

聽說有五個

<要丟給電腦算>

Update:

cloud

我用FrontPage開無法顯示

能傳檔寄給我

sing_ja@yahoo.com.tw

Update 2:

給:cloud

對了

我要的就是這個答案

但我必須顯示在網頁上出了問題能說明一下嗎?

2 Answers

Rating
  • cloud
    Lv 4
    1 decade ago
    Favorite Answer

    只有一對照順序的 + - 是無解的

    因此以下是以數字照順序, + - 可任意插入為規則來考慮

    只是結果不止五組

    不過邏輯應該大同小異, 可以參照改成你要的

    結果 :

    1+2+3-4+5+6+78+9=100

    1+2+34-5+67-8+9=100

    1+23-4+5+6+78-9=100

    1+23-4+56+7+8+9=100

    12+3+4+5-6-7+89=100

    12+3-4+5+67+8+9=100

    12-3-4+5-6+7+89=100

    123+4-5+67-89=100

    123+45-67+8-9=100

    123-4-5-6-7+8-9=100

    123-45-67+89=100

    <script language="JavaScript">

    function init() {

     var str = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9");

     var oper = new Array("a", "m", "");

     for (var i1 = 0; i1 < 3; i1++) {

      for (var i2 = 0; i2 < 3; i2++) {

       for (var i3 = 0; i3 < 3; i3++) {

        for (var i4 = 0; i4 < 3; i4++) {

         for (var i5 = 0; i5 < 3; i5++) {

          for (var i6 = 0; i6 < 3; i6++) {

           for (var i7 = 0; i7 < 3; i7++) {

            for (var i8 = 0; i8 < 3; i8++) {

             count(str[0] + oper[i1] + str[1] + oper[i2] + str[2] + oper[i3]

               + str[3] + oper[i4] + str[4] + oper[i5] + str[5] + oper[i6]

               + str[6] + oper[i7] + str[7] + oper[i8] + str[8]);

            }

           }

          }

         }

        }

       }

      }

     }

    }

    function count(str) {

     var sum = 0;

     var oper = "";

     var add = str.split("a");

     for (var i = 0; i < add.length; i++) {

      var minus = add[i].split("m");

      sum += parseInt(minus[0]);

      oper += i == 0 ? minus[0] : "+" + minus[0];

      for (var j = 1; j < minus.length; j++) {

       sum -= parseInt(minus[j]);

       oper += "-" + minus[j];

      }

      

     }

     if (sum == 100) {

      document.write(oper + "=100<br>\n");

     }

    }

    </script>

    2007-12-14 00:46:42 補充:

    這是 script code

    你要把它放在 html 網頁裡面

    一般習慣是放在 head tag 裡

    然後在 body tag 裡設 onload="init()"

    就可以 run 了

    • Commenter avatarLogin to reply the answers
  • 1 decade ago

    1+2-3456789=-3456786

    1+23-456789=-456765

    1+234-56789=-56554

    1+2345-6789=-4443

    1+23456-789=22668

    1+234567-89=234479

    1+2345678-9=2345670

    12+3-456789=-456774

    12+34-56789=-56743

    12+345-6789=-6432

    12+3456-789=2679

    12+34567-89=34490

    12+345678-9=345681

    2007-12-12 16:41:10 補充:

    123+4-56789=-56662

    123+45-6789=-6621

    123+456-789=-210

    123+4567-89=4601

    123+45678-9=45792

    1234+5-6789=-5550

    1234+56-789=501

    1234+567-89=1712

    1234+5678-9=6903

    12345+6-789=11562

    12345+67-89=12323

    12345+678-9=13014

    123456+7-89=123374

    123456+78-9=123525

    1234567+8-9=1234566

    沒有等於 100 的解

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.