<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년 전 | 3972 | ||
| 129 | 20년 전 | 2913 | ||
| 128 | 20년 전 | 3649 | ||
| 127 | 20년 전 | 3461 | ||
| 126 | 20년 전 | 3733 | ||
| 125 | 20년 전 | 8566 | ||
| 124 | 20년 전 | 2590 | ||
| 123 | 20년 전 | 3735 | ||
| 122 | 20년 전 | 3194 | ||
| 121 | 20년 전 | 2596 | ||
| 120 | 20년 전 | 2653 | ||
| 119 | 20년 전 | 2569 | ||
| 118 | 20년 전 | 2854 | ||
| 117 |
|
20년 전 | 3042 | |
| 116 | 20년 전 | 5291 | ||
| 115 | 20년 전 | 3901 | ||
| 114 | 20년 전 | 4950 | ||
| 113 | 20년 전 | 6196 | ||
| 112 | 20년 전 | 7317 | ||
| 111 | 20년 전 | 18422 | ||
| 110 | 20년 전 | 6868 | ||
| 109 | 20년 전 | 2868 | ||
| 108 | 20년 전 | 4127 | ||
| 107 |
prosper
|
20년 전 | 2479 | |
| 106 |
prosper
|
20년 전 | 4302 | |
| 105 |
아우겐나이스
|
20년 전 | 2896 | |
| 104 | 20년 전 | 2249 | ||
| 103 | 20년 전 | 2467 | ||
| 102 | 20년 전 | 2228 | ||
| 101 | 20년 전 | 2557 | ||
| 100 | 20년 전 | 1736 | ||
| 99 | 20년 전 | 1559 | ||
| 98 | 20년 전 | 1609 | ||
| 97 | 20년 전 | 2113 | ||
| 96 | 20년 전 | 1863 | ||
| 95 | 20년 전 | 2362 | ||
| 94 | 20년 전 | 3549 | ||
| 93 | 20년 전 | 1547 | ||
| 92 | 20년 전 | 1745 | ||
| 91 | 20년 전 | 3162 | ||
| 90 | 20년 전 | 2334 | ||
| 89 | 20년 전 | 3158 | ||
| 88 | 20년 전 | 2859 | ||
| 87 | 20년 전 | 3285 | ||
| 86 | 20년 전 | 5109 | ||
| 85 | 20년 전 | 2509 | ||
| 84 | 20년 전 | 4814 | ||
| 83 | 20년 전 | 2492 | ||
| 82 | 20년 전 | 3106 | ||
| 81 | 20년 전 | 7610 | ||
| 80 | 20년 전 | 3809 | ||
| 79 | 20년 전 | 3198 | ||
| 78 | 20년 전 | 4680 | ||
| 77 | 20년 전 | 2886 | ||
| 76 | 20년 전 | 6206 | ||
| 75 | 20년 전 | 4462 | ||
| 74 | 20년 전 | 5771 | ||
| 73 | 20년 전 | 3617 | ||
| 72 | 20년 전 | 5956 | ||
| 71 | 20년 전 | 3098 | ||
| 70 | 20년 전 | 2827 | ||
| 69 | 20년 전 | 2624 | ||
| 68 | 20년 전 | 2432 | ||
| 67 | 20년 전 | 2641 | ||
| 66 | 20년 전 | 2660 | ||
| 65 | 20년 전 | 3779 | ||
| 64 | 20년 전 | 2813 | ||
| 63 | 20년 전 | 2445 | ||
| 62 | 20년 전 | 2251 | ||
| 61 | 20년 전 | 3051 | ||
| 60 | 20년 전 | 3122 | ||
| 59 | 20년 전 | 2501 | ||
| 58 | 20년 전 | 2584 | ||
| 57 | 20년 전 | 2955 | ||
| 56 | 20년 전 | 2300 | ||
| 55 | 20년 전 | 2746 | ||
| 54 | 20년 전 | 2112 | ||
| 53 | 20년 전 | 2337 | ||
| 52 | 20년 전 | 2685 | ||
| 51 |
prosper
|
20년 전 | 2338 | |
| 50 |
prosper
|
20년 전 | 2156 | |
| 49 | 21년 전 | 2165 | ||
| 48 | 21년 전 | 2317 | ||
| 47 | 21년 전 | 1918 | ||
| 46 | 21년 전 | 1917 | ||
| 45 | 21년 전 | 2124 | ||
| 44 | 21년 전 | 2350 | ||
| 43 | 21년 전 | 4565 | ||
| 42 |
prosper
|
21년 전 | 2702 | |
| 41 |
prosper
|
21년 전 | 2105 | |
| 40 | 21년 전 | 2170 | ||
| 39 | 21년 전 | 2136 | ||
| 38 | 21년 전 | 2404 | ||
| 37 | 21년 전 | 2552 | ||
| 36 | 21년 전 | 1766 | ||
| 35 | 21년 전 | 4062 | ||
| 34 | 21년 전 | 3839 | ||
| 33 | 21년 전 | 2981 | ||
| 32 |
prosper
|
21년 전 | 2889 | |
| 31 | 21년 전 | 5263 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기