<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="" />
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7630 | 10년 전 | 651 | ||
| 7629 |
|
10년 전 | 2385 | |
| 7628 | 10년 전 | 791 | ||
| 7627 |
|
10년 전 | 1028 | |
| 7626 |
|
10년 전 | 1786 | |
| 7625 | 10년 전 | 703 | ||
| 7624 | 10년 전 | 722 | ||
| 7623 |
|
10년 전 | 3085 | |
| 7622 | 10년 전 | 725 | ||
| 7621 |
leeleeleelee
|
10년 전 | 584 | |
| 7620 | 10년 전 | 539 | ||
| 7619 | 10년 전 | 481 | ||
| 7618 | 10년 전 | 1021 | ||
| 7617 | 10년 전 | 724 | ||
| 7616 | 10년 전 | 641 | ||
| 7615 | 10년 전 | 726 | ||
| 7614 | 10년 전 | 1258 | ||
| 7613 |
|
10년 전 | 2084 | |
| 7612 | 10년 전 | 1140 | ||
| 7611 | 10년 전 | 1411 | ||
| 7610 |
|
10년 전 | 1901 | |
| 7609 |
|
10년 전 | 1339 | |
| 7608 |
mwdkim
|
10년 전 | 1130 | |
| 7607 |
|
10년 전 | 1052 | |
| 7606 |
mwdkim
|
10년 전 | 3926 | |
| 7605 | 10년 전 | 690 | ||
| 7604 | 10년 전 | 1026 | ||
| 7603 | 10년 전 | 1650 | ||
| 7602 |
|
10년 전 | 1076 | |
| 7601 |
AniNest
|
10년 전 | 2789 | |
| 7600 |
port443
|
10년 전 | 1029 | |
| 7599 | 10년 전 | 943 | ||
| 7598 | 10년 전 | 1017 | ||
| 7597 | 10년 전 | 4571 | ||
| 7596 |
SeungYeon
|
10년 전 | 888 | |
| 7595 |
untitled
|
10년 전 | 2422 | |
| 7594 |
프로그래머7
|
10년 전 | 1725 | |
| 7593 |
untitled
|
10년 전 | 2364 | |
| 7592 |
untitled
|
10년 전 | 1937 | |
| 7591 |
untitled
|
10년 전 | 2675 | |
| 7590 |
아리마2001
|
10년 전 | 852 | |
| 7589 | 10년 전 | 1110 | ||
| 7588 |
|
10년 전 | 2919 | |
| 7587 | 10년 전 | 1302 | ||
| 7586 | 10년 전 | 669 | ||
| 7585 | 10년 전 | 1693 | ||
| 7584 | 10년 전 | 1411 | ||
| 7583 |
leeleeleelee
|
10년 전 | 1160 | |
| 7582 |
|
10년 전 | 1110 | |
| 7581 | 10년 전 | 1338 | ||
| 7580 | 10년 전 | 989 | ||
| 7579 |
|
10년 전 | 606 | |
| 7578 | 10년 전 | 1429 | ||
| 7577 |
|
10년 전 | 1871 | |
| 7576 | 10년 전 | 1385 | ||
| 7575 |
멋진남자임
|
10년 전 | 1460 | |
| 7574 | 10년 전 | 2121 | ||
| 7573 | 10년 전 | 3251 | ||
| 7572 | 10년 전 | 760 | ||
| 7571 |
|
10년 전 | 781 | |
| 7570 |
|
10년 전 | 1313 | |
| 7569 | 10년 전 | 1549 | ||
| 7568 |
this1mg
|
10년 전 | 1048 | |
| 7567 |
|
10년 전 | 759 | |
| 7566 | 10년 전 | 915 | ||
| 7565 |
Angel하늘
|
10년 전 | 998 | |
| 7564 |
seoldi
|
10년 전 | 1237 | |
| 7563 |
|
10년 전 | 1379 | |
| 7562 |
멋진남자임
|
10년 전 | 2084 | |
| 7561 | 10년 전 | 713 | ||
| 7560 |
leeleeleelee
|
10년 전 | 903 | |
| 7559 | 10년 전 | 5046 | ||
| 7558 |
RinaP
|
10년 전 | 782 | |
| 7557 |
|
10년 전 | 1242 | |
| 7556 | 10년 전 | 1191 | ||
| 7555 |
hyohyojj1234
|
10년 전 | 1662 | |
| 7554 | 10년 전 | 1091 | ||
| 7553 |
senseme
|
10년 전 | 1337 | |
| 7552 |
ehdltdoit
|
10년 전 | 1435 | |
| 7551 |
|
10년 전 | 1821 | |
| 7550 |
leeleeleelee
|
10년 전 | 1587 | |
| 7549 | 10년 전 | 2419 | ||
| 7548 | 10년 전 | 1838 | ||
| 7547 |
멋진남자임
|
10년 전 | 1960 | |
| 7546 | 10년 전 | 1002 | ||
| 7545 |
ILMare1003
|
10년 전 | 1286 | |
| 7544 |
|
10년 전 | 1250 | |
| 7543 | 10년 전 | 884 | ||
| 7542 | 10년 전 | 656 | ||
| 7541 |
울라라라우
|
10년 전 | 864 | |
| 7540 | 10년 전 | 1600 | ||
| 7539 | 10년 전 | 934 | ||
| 7538 |
|
10년 전 | 1832 | |
| 7537 | 10년 전 | 3610 | ||
| 7536 |
Gaumi
|
10년 전 | 1414 | |
| 7535 |
프로그램은어려워
|
10년 전 | 1271 | |
| 7534 |
senseme
|
10년 전 | 1206 | |
| 7533 | 10년 전 | 1194 | ||
| 7532 | 10년 전 | 857 | ||
| 7531 | 10년 전 | 2050 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기