<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="" />
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 930 | 19년 전 | 3543 | ||
| 929 |
|
19년 전 | 2703 | |
| 928 |
|
19년 전 | 3455 | |
| 927 |
|
19년 전 | 3442 | |
| 926 |
|
19년 전 | 3148 | |
| 925 | 19년 전 | 5434 | ||
| 924 |
|
19년 전 | 2168 | |
| 923 |
|
19년 전 | 2219 | |
| 922 |
|
19년 전 | 2314 | |
| 921 |
|
19년 전 | 3407 | |
| 920 | 19년 전 | 3708 | ||
| 919 |
|
19년 전 | 3746 | |
| 918 |
|
19년 전 | 2365 | |
| 917 |
|
19년 전 | 2399 | |
| 916 |
|
19년 전 | 2702 | |
| 915 | 19년 전 | 3045 | ||
| 914 | 19년 전 | 2459 | ||
| 913 | 19년 전 | 2626 | ||
| 912 | 19년 전 | 2461 | ||
| 911 | 19년 전 | 2214 | ||
| 910 | 19년 전 | 3245 | ||
| 909 | 19년 전 | 3298 | ||
| 908 | 19년 전 | 3038 | ||
| 907 |
|
19년 전 | 4874 | |
| 906 |
|
19년 전 | 2714 | |
| 905 |
|
19년 전 | 3317 | |
| 904 |
|
19년 전 | 3146 | |
| 903 |
|
19년 전 | 1995 | |
| 902 |
|
19년 전 | 3139 | |
| 901 |
|
19년 전 | 1878 | |
| 900 |
|
19년 전 | 2337 | |
| 899 |
|
19년 전 | 2402 | |
| 898 |
|
19년 전 | 3984 | |
| 897 |
|
19년 전 | 3186 | |
| 896 |
|
19년 전 | 3101 | |
| 895 |
|
19년 전 | 2538 | |
| 894 |
|
19년 전 | 2016 | |
| 893 |
|
19년 전 | 1645 | |
| 892 |
|
19년 전 | 2416 | |
| 891 |
|
19년 전 | 2330 | |
| 890 |
|
19년 전 | 1815 | |
| 889 |
|
19년 전 | 1810 | |
| 888 |
|
19년 전 | 2610 | |
| 887 |
|
19년 전 | 2580 | |
| 886 |
|
19년 전 | 1875 | |
| 885 |
|
19년 전 | 2112 | |
| 884 |
|
19년 전 | 3303 | |
| 883 |
|
19년 전 | 1952 | |
| 882 |
|
19년 전 | 2501 | |
| 881 |
|
19년 전 | 2581 | |
| 880 |
|
19년 전 | 2662 | |
| 879 |
|
19년 전 | 2939 | |
| 878 |
|
19년 전 | 2559 | |
| 877 |
|
19년 전 | 2984 | |
| 876 |
|
19년 전 | 2761 | |
| 875 |
|
19년 전 | 3522 | |
| 874 | 19년 전 | 1871 | ||
| 873 | 19년 전 | 2735 | ||
| 872 |
|
19년 전 | 2375 | |
| 871 |
|
19년 전 | 2019 | |
| 870 |
|
19년 전 | 2427 | |
| 869 |
|
19년 전 | 1871 | |
| 868 |
|
19년 전 | 5439 | |
| 867 |
|
19년 전 | 2261 | |
| 866 |
|
19년 전 | 4260 | |
| 865 |
|
19년 전 | 2302 | |
| 864 | 19년 전 | 1850 | ||
| 863 | 19년 전 | 2605 | ||
| 862 | 19년 전 | 2332 | ||
| 861 | 19년 전 | 2533 | ||
| 860 | 19년 전 | 2160 | ||
| 859 | 19년 전 | 3925 | ||
| 858 | 19년 전 | 3417 | ||
| 857 | 19년 전 | 2198 | ||
| 856 |
Power
|
19년 전 | 2106 | |
| 855 | 19년 전 | 1971 | ||
| 854 | 19년 전 | 2003 | ||
| 853 |
pearly
|
19년 전 | 4387 | |
| 852 |
pearly
|
19년 전 | 3358 | |
| 851 | 19년 전 | 2773 | ||
| 850 |
pearly
|
19년 전 | 3353 | |
| 849 |
pearly
|
19년 전 | 3013 | |
| 848 |
pearly
|
19년 전 | 2841 | |
| 847 | 19년 전 | 2361 | ||
| 846 |
|
19년 전 | 2172 | |
| 845 |
pearly
|
19년 전 | 2492 | |
| 844 | 19년 전 | 3103 | ||
| 843 | 19년 전 | 2133 | ||
| 842 |
pearly
|
19년 전 | 3123 | |
| 841 |
pearly
|
19년 전 | 3245 | |
| 840 | 19년 전 | 2927 | ||
| 839 |
|
19년 전 | 1941 | |
| 838 |
|
19년 전 | 1706 | |
| 837 |
|
19년 전 | 2327 | |
| 836 |
|
19년 전 | 2270 | |
| 835 |
|
19년 전 | 1645 | |
| 834 |
|
19년 전 | 1666 | |
| 833 |
|
19년 전 | 1573 | |
| 832 |
|
19년 전 | 2067 | |
| 831 |
|
19년 전 | 1616 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기