<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="" />
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8230 | 9년 전 | 62 | ||
| 8229 | 9년 전 | 62 | ||
| 8228 |
커네드커네드
|
9년 전 | 108 | |
| 8227 | 9년 전 | 115 | ||
| 8226 | 9년 전 | 156 | ||
| 8225 | 9년 전 | 143 | ||
| 8224 | 9년 전 | 141 | ||
| 8223 | 9년 전 | 110 | ||
| 8222 |
|
9년 전 | 176 | |
| 8221 | 9년 전 | 81 | ||
| 8220 | 9년 전 | 91 | ||
| 8219 | 9년 전 | 94 | ||
| 8218 | 9년 전 | 129 | ||
| 8217 |
star3840
|
9년 전 | 104 | |
| 8216 | 9년 전 | 156 | ||
| 8215 | 9년 전 | 101 | ||
| 8214 | 9년 전 | 218 | ||
| 8213 | 9년 전 | 149 | ||
| 8212 | 9년 전 | 77 | ||
| 8211 | 9년 전 | 236 | ||
| 8210 | 9년 전 | 237 | ||
| 8209 | 9년 전 | 328 | ||
| 8208 | 9년 전 | 208 | ||
| 8207 | 9년 전 | 217 | ||
| 8206 |
|
9년 전 | 176 | |
| 8205 | 9년 전 | 162 | ||
| 8204 | 9년 전 | 123 | ||
| 8203 | 9년 전 | 224 | ||
| 8202 | 9년 전 | 134 | ||
| 8201 | 9년 전 | 174 | ||
| 8200 | 9년 전 | 150 | ||
| 8199 | 9년 전 | 201 | ||
| 8198 | 9년 전 | 166 | ||
| 8197 | 9년 전 | 154 | ||
| 8196 | 9년 전 | 543 | ||
| 8195 | 9년 전 | 149 | ||
| 8194 | 9년 전 | 276 | ||
| 8193 | 9년 전 | 150 | ||
| 8192 | 9년 전 | 177 | ||
| 8191 | 9년 전 | 131 | ||
| 8190 | 9년 전 | 123 | ||
| 8189 | 9년 전 | 181 | ||
| 8188 | 9년 전 | 123 | ||
| 8187 | 9년 전 | 135 | ||
| 8186 | 9년 전 | 136 | ||
| 8185 | 9년 전 | 302 | ||
| 8184 | 9년 전 | 99 | ||
| 8183 | 9년 전 | 318 | ||
| 8182 | 9년 전 | 160 | ||
| 8181 | 9년 전 | 121 | ||
| 8180 | 9년 전 | 688 | ||
| 8179 | 9년 전 | 479 | ||
| 8178 | 9년 전 | 299 | ||
| 8177 |
kiplayer
|
9년 전 | 305 | |
| 8176 | 9년 전 | 343 | ||
| 8175 | 9년 전 | 212 | ||
| 8174 | 9년 전 | 231 | ||
| 8173 | 9년 전 | 340 | ||
| 8172 | 9년 전 | 186 | ||
| 8171 | 9년 전 | 178 | ||
| 8170 | 9년 전 | 287 | ||
| 8169 |
커네드커네드
|
9년 전 | 251 | |
| 8168 | 9년 전 | 311 | ||
| 8167 | 9년 전 | 312 | ||
| 8166 | 9년 전 | 229 | ||
| 8165 | 9년 전 | 158 | ||
| 8164 | 9년 전 | 297 | ||
| 8163 | 9년 전 | 277 | ||
| 8162 | 9년 전 | 292 | ||
| 8161 | 9년 전 | 285 | ||
| 8160 |
|
9년 전 | 482 | |
| 8159 | 9년 전 | 417 | ||
| 8158 | 9년 전 | 232 | ||
| 8157 | 9년 전 | 365 | ||
| 8156 | 9년 전 | 272 | ||
| 8155 | 9년 전 | 246 | ||
| 8154 |
00년생용띠
|
9년 전 | 594 | |
| 8153 | 9년 전 | 222 | ||
| 8152 |
|
9년 전 | 397 | |
| 8151 | 9년 전 | 399 | ||
| 8150 | 9년 전 | 493 | ||
| 8149 |
Jangfolk
|
9년 전 | 336 | |
| 8148 | 9년 전 | 159 | ||
| 8147 | 9년 전 | 366 | ||
| 8146 | 9년 전 | 425 | ||
| 8145 | 9년 전 | 369 | ||
| 8144 | 9년 전 | 337 | ||
| 8143 | 9년 전 | 183 | ||
| 8142 | 9년 전 | 422 | ||
| 8141 | 9년 전 | 375 | ||
| 8140 | 9년 전 | 920 | ||
| 8139 | 9년 전 | 252 | ||
| 8138 |
전갈자리남자
|
9년 전 | 380 | |
| 8137 | 9년 전 | 383 | ||
| 8136 | 9년 전 | 737 | ||
| 8135 |
|
9년 전 | 785 | |
| 8134 |
PlayPixel
|
9년 전 | 503 | |
| 8133 |
|
9년 전 | 428 | |
| 8132 | 9년 전 | 440 | ||
| 8131 | 9년 전 | 804 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기