<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년 전 | 164 | ||
| 8229 | 9년 전 | 140 | ||
| 8228 |
커네드커네드
|
9년 전 | 184 | |
| 8227 | 9년 전 | 227 | ||
| 8226 | 9년 전 | 243 | ||
| 8225 | 9년 전 | 225 | ||
| 8224 | 9년 전 | 232 | ||
| 8223 | 9년 전 | 211 | ||
| 8222 |
|
9년 전 | 269 | |
| 8221 | 9년 전 | 172 | ||
| 8220 | 9년 전 | 208 | ||
| 8219 | 9년 전 | 180 | ||
| 8218 | 9년 전 | 231 | ||
| 8217 |
star3840
|
9년 전 | 196 | |
| 8216 | 9년 전 | 260 | ||
| 8215 | 9년 전 | 205 | ||
| 8214 | 9년 전 | 324 | ||
| 8213 | 9년 전 | 278 | ||
| 8212 | 9년 전 | 180 | ||
| 8211 | 9년 전 | 358 | ||
| 8210 | 9년 전 | 356 | ||
| 8209 | 9년 전 | 434 | ||
| 8208 | 9년 전 | 323 | ||
| 8207 | 9년 전 | 332 | ||
| 8206 |
|
9년 전 | 278 | |
| 8205 | 9년 전 | 251 | ||
| 8204 | 9년 전 | 238 | ||
| 8203 | 9년 전 | 315 | ||
| 8202 | 9년 전 | 232 | ||
| 8201 | 9년 전 | 262 | ||
| 8200 | 9년 전 | 276 | ||
| 8199 | 9년 전 | 300 | ||
| 8198 | 9년 전 | 261 | ||
| 8197 | 9년 전 | 248 | ||
| 8196 | 9년 전 | 669 | ||
| 8195 | 9년 전 | 259 | ||
| 8194 | 9년 전 | 370 | ||
| 8193 | 9년 전 | 276 | ||
| 8192 | 9년 전 | 290 | ||
| 8191 | 9년 전 | 246 | ||
| 8190 | 9년 전 | 229 | ||
| 8189 | 9년 전 | 296 | ||
| 8188 | 9년 전 | 224 | ||
| 8187 | 9년 전 | 237 | ||
| 8186 | 9년 전 | 231 | ||
| 8185 | 9년 전 | 404 | ||
| 8184 | 9년 전 | 189 | ||
| 8183 | 9년 전 | 400 | ||
| 8182 | 9년 전 | 270 | ||
| 8181 | 9년 전 | 227 | ||
| 8180 | 9년 전 | 793 | ||
| 8179 | 9년 전 | 570 | ||
| 8178 | 9년 전 | 434 | ||
| 8177 |
kiplayer
|
9년 전 | 428 | |
| 8176 | 9년 전 | 458 | ||
| 8175 | 9년 전 | 352 | ||
| 8174 | 9년 전 | 340 | ||
| 8173 | 9년 전 | 432 | ||
| 8172 | 9년 전 | 308 | ||
| 8171 | 9년 전 | 272 | ||
| 8170 | 9년 전 | 387 | ||
| 8169 |
커네드커네드
|
9년 전 | 345 | |
| 8168 | 9년 전 | 425 | ||
| 8167 | 9년 전 | 413 | ||
| 8166 | 9년 전 | 314 | ||
| 8165 | 9년 전 | 260 | ||
| 8164 | 9년 전 | 393 | ||
| 8163 | 9년 전 | 397 | ||
| 8162 | 9년 전 | 383 | ||
| 8161 | 9년 전 | 399 | ||
| 8160 |
|
9년 전 | 615 | |
| 8159 | 9년 전 | 559 | ||
| 8158 | 9년 전 | 354 | ||
| 8157 | 9년 전 | 467 | ||
| 8156 | 9년 전 | 348 | ||
| 8155 | 9년 전 | 352 | ||
| 8154 |
00년생용띠
|
9년 전 | 683 | |
| 8153 | 9년 전 | 319 | ||
| 8152 |
|
9년 전 | 500 | |
| 8151 | 9년 전 | 499 | ||
| 8150 | 9년 전 | 611 | ||
| 8149 |
Jangfolk
|
9년 전 | 468 | |
| 8148 | 9년 전 | 283 | ||
| 8147 | 9년 전 | 464 | ||
| 8146 | 9년 전 | 551 | ||
| 8145 | 9년 전 | 505 | ||
| 8144 | 9년 전 | 474 | ||
| 8143 | 9년 전 | 305 | ||
| 8142 | 9년 전 | 515 | ||
| 8141 | 9년 전 | 459 | ||
| 8140 | 9년 전 | 1024 | ||
| 8139 | 9년 전 | 375 | ||
| 8138 |
전갈자리남자
|
9년 전 | 476 | |
| 8137 | 9년 전 | 515 | ||
| 8136 | 9년 전 | 845 | ||
| 8135 |
|
9년 전 | 884 | |
| 8134 |
PlayPixel
|
9년 전 | 621 | |
| 8133 |
|
9년 전 | 530 | |
| 8132 | 9년 전 | 570 | ||
| 8131 | 9년 전 | 927 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기