<script>
function getOpPrec(op) {
switch(op) {
case '*': case '/':
return 5;
case '+': case '-':
return 3;
case '(':
return 1;
}
}
function whoPrecOp(op1, op2) {
var op1Prec = getOpPrec(op1), op2Prec = getOpPrec(op2);
if (op1Prec > op2Prec)
return 1;
else if (op1Prec < op2Prec)
return -1;
else
return 0;
}
function postfix(exp) {
var dst = [], src = [], op = [],
src = exp.replace(' ','').match(/[\d\.]+|[+\-*()/]/g);
while (src.length) {
var tok = src.shift();
if (!isNaN(tok)) {
dst.push(tok);
} else {
switch(tok) {
case '(':
op.push(tok);
break;
case ')':
while(1) {
var popOp = op.pop();
if (popOp == '(')
break;
dst.push(popOp);
}
break;
case '+': case '-':
case '*': case '/':
while (op.length && whoPrecOp(op[op.length-1], tok) > 0)
dst.push(op.pop());
op.push(tok);
break;
}
}
}
while (op.length)
dst.push(op.pop());
return dst;
}
function evalExp(exp) {
var dst = [], op1, op2;
while (exp.length) {
var tok = exp.shift();
if (!isNaN(tok))
dst.push(tok);
else {
op2 = Number(dst.pop());
op1 = Number(dst.pop());
switch (tok) {
case '+':
dst.push(op1 + op2);
break;
case '-':
dst.push(op1 - op2);
break;
case '*':
dst.push(op1 * op2);
break;
case '/':
dst.push(op1 / op2);
break;
}
}
}
return dst;
}
function cal(src) {
document.getElementById('result').value = evalExp(postfix(src));
}
</script>
입력 <input type="text" id="input" name="src" value="" onblur="cal(this.value)" /> =
결과 <input id="result" type="text" name="result" size="10" value="" />
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 130 | 20년 전 | 3971 | ||
| 129 | 20년 전 | 2913 | ||
| 128 | 20년 전 | 3648 | ||
| 127 | 20년 전 | 3458 | ||
| 126 | 20년 전 | 3730 | ||
| 125 | 20년 전 | 8564 | ||
| 124 | 20년 전 | 2589 | ||
| 123 | 20년 전 | 3735 | ||
| 122 | 20년 전 | 3194 | ||
| 121 | 20년 전 | 2595 | ||
| 120 | 20년 전 | 2652 | ||
| 119 | 20년 전 | 2567 | ||
| 118 | 20년 전 | 2853 | ||
| 117 |
|
20년 전 | 3040 | |
| 116 | 20년 전 | 5290 | ||
| 115 | 20년 전 | 3900 | ||
| 114 | 20년 전 | 4949 | ||
| 113 | 20년 전 | 6196 | ||
| 112 | 20년 전 | 7317 | ||
| 111 | 20년 전 | 18421 | ||
| 110 | 20년 전 | 6868 | ||
| 109 | 20년 전 | 2868 | ||
| 108 | 20년 전 | 4127 | ||
| 107 |
prosper
|
20년 전 | 2476 | |
| 106 |
prosper
|
20년 전 | 4301 | |
| 105 |
아우겐나이스
|
20년 전 | 2895 | |
| 104 | 20년 전 | 2249 | ||
| 103 | 20년 전 | 2465 | ||
| 102 | 20년 전 | 2226 | ||
| 101 | 20년 전 | 2556 | ||
| 100 | 20년 전 | 1736 | ||
| 99 | 20년 전 | 1558 | ||
| 98 | 20년 전 | 1609 | ||
| 97 | 20년 전 | 2113 | ||
| 96 | 20년 전 | 1863 | ||
| 95 | 20년 전 | 2362 | ||
| 94 | 20년 전 | 3549 | ||
| 93 | 20년 전 | 1547 | ||
| 92 | 20년 전 | 1745 | ||
| 91 | 20년 전 | 3161 | ||
| 90 | 20년 전 | 2334 | ||
| 89 | 20년 전 | 3158 | ||
| 88 | 20년 전 | 2859 | ||
| 87 | 20년 전 | 3284 | ||
| 86 | 20년 전 | 5109 | ||
| 85 | 20년 전 | 2509 | ||
| 84 | 20년 전 | 4811 | ||
| 83 | 20년 전 | 2490 | ||
| 82 | 20년 전 | 3105 | ||
| 81 | 20년 전 | 7610 | ||
| 80 | 20년 전 | 3808 | ||
| 79 | 20년 전 | 3197 | ||
| 78 | 20년 전 | 4679 | ||
| 77 | 20년 전 | 2885 | ||
| 76 | 20년 전 | 6206 | ||
| 75 | 20년 전 | 4462 | ||
| 74 | 20년 전 | 5771 | ||
| 73 | 20년 전 | 3617 | ||
| 72 | 20년 전 | 5955 | ||
| 71 | 20년 전 | 3096 | ||
| 70 | 20년 전 | 2827 | ||
| 69 | 20년 전 | 2623 | ||
| 68 | 20년 전 | 2432 | ||
| 67 | 20년 전 | 2639 | ||
| 66 | 20년 전 | 2659 | ||
| 65 | 20년 전 | 3779 | ||
| 64 | 20년 전 | 2812 | ||
| 63 | 20년 전 | 2445 | ||
| 62 | 20년 전 | 2251 | ||
| 61 | 20년 전 | 3049 | ||
| 60 | 20년 전 | 3121 | ||
| 59 | 20년 전 | 2500 | ||
| 58 | 20년 전 | 2581 | ||
| 57 | 20년 전 | 2954 | ||
| 56 | 20년 전 | 2300 | ||
| 55 | 20년 전 | 2745 | ||
| 54 | 20년 전 | 2112 | ||
| 53 | 20년 전 | 2337 | ||
| 52 | 20년 전 | 2684 | ||
| 51 |
prosper
|
20년 전 | 2336 | |
| 50 |
prosper
|
20년 전 | 2155 | |
| 49 | 20년 전 | 2163 | ||
| 48 | 20년 전 | 2317 | ||
| 47 | 20년 전 | 1917 | ||
| 46 | 20년 전 | 1917 | ||
| 45 | 20년 전 | 2123 | ||
| 44 | 20년 전 | 2350 | ||
| 43 | 21년 전 | 4564 | ||
| 42 |
prosper
|
21년 전 | 2702 | |
| 41 |
prosper
|
21년 전 | 2104 | |
| 40 | 21년 전 | 2168 | ||
| 39 | 21년 전 | 2135 | ||
| 38 | 21년 전 | 2402 | ||
| 37 | 21년 전 | 2551 | ||
| 36 | 21년 전 | 1766 | ||
| 35 | 21년 전 | 4062 | ||
| 34 | 21년 전 | 3839 | ||
| 33 | 21년 전 | 2981 | ||
| 32 |
prosper
|
21년 전 | 2889 | |
| 31 | 21년 전 | 5261 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기