<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="" />
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 430 | 19년 전 | 4092 | ||
| 429 | 19년 전 | 3288 | ||
| 428 | 19년 전 | 4123 | ||
| 427 | 19년 전 | 3465 | ||
| 426 | 19년 전 | 3098 | ||
| 425 | 19년 전 | 3393 | ||
| 424 | 19년 전 | 2434 | ||
| 423 | 19년 전 | 2851 | ||
| 422 | 19년 전 | 2342 | ||
| 421 | 19년 전 | 3702 | ||
| 420 | 19년 전 | 4728 | ||
| 419 | 19년 전 | 3783 | ||
| 418 |
|
19년 전 | 1732 | |
| 417 | 19년 전 | 2738 | ||
| 416 | 19년 전 | 2384 | ||
| 415 | 19년 전 | 2601 | ||
| 414 | 19년 전 | 4399 | ||
| 413 |
|
19년 전 | 2585 | |
| 412 | 19년 전 | 3034 | ||
| 411 |
|
19년 전 | 2981 | |
| 410 |
|
19년 전 | 3670 | |
| 409 |
|
19년 전 | 3624 | |
| 408 |
|
19년 전 | 1847 | |
| 407 | 19년 전 | 2221 | ||
| 406 | 19년 전 | 2772 | ||
| 405 | 19년 전 | 2437 | ||
| 404 | 19년 전 | 4292 | ||
| 403 | 19년 전 | 3298 | ||
| 402 |
NeoGenesis
|
19년 전 | 4084 | |
| 401 | 19년 전 | 2596 | ||
| 400 |
|
19년 전 | 2486 | |
| 399 | 19년 전 | 2946 | ||
| 398 | 19년 전 | 2479 | ||
| 397 | 19년 전 | 2776 | ||
| 396 | 19년 전 | 2462 | ||
| 395 | 19년 전 | 3172 | ||
| 394 | 19년 전 | 1707 | ||
| 393 | 19년 전 | 2985 | ||
| 392 | 19년 전 | 2242 | ||
| 391 | 19년 전 | 2174 | ||
| 390 | 19년 전 | 2273 | ||
| 389 | 19년 전 | 2638 | ||
| 388 | 19년 전 | 2141 | ||
| 387 | 19년 전 | 4476 | ||
| 386 |
|
19년 전 | 2676 | |
| 385 |
|
19년 전 | 2470 | |
| 384 | 19년 전 | 2997 | ||
| 383 | 19년 전 | 3040 | ||
| 382 | 19년 전 | 3095 | ||
| 381 |
|
19년 전 | 2624 | |
| 380 |
|
19년 전 | 3005 | |
| 379 | 19년 전 | 2541 | ||
| 378 | 19년 전 | 2200 | ||
| 377 | 19년 전 | 2774 | ||
| 376 | 19년 전 | 2465 | ||
| 375 |
|
19년 전 | 2550 | |
| 374 | 19년 전 | 3802 | ||
| 373 | 19년 전 | 3259 | ||
| 372 | 19년 전 | 4980 | ||
| 371 |
세은아빠2
|
19년 전 | 2406 | |
| 370 | 19년 전 | 4495 | ||
| 369 | 19년 전 | 3102 | ||
| 368 | 19년 전 | 2885 | ||
| 367 | 19년 전 | 3720 | ||
| 366 | 19년 전 | 2632 | ||
| 365 | 19년 전 | 3725 | ||
| 364 | 19년 전 | 4004 | ||
| 363 | 19년 전 | 3428 | ||
| 362 | 19년 전 | 3470 | ||
| 361 | 19년 전 | 4093 | ||
| 360 |
hwatta
|
19년 전 | 2352 | |
| 359 | 19년 전 | 5092 | ||
| 358 | 19년 전 | 3647 | ||
| 357 | 19년 전 | 2585 | ||
| 356 |
sdesign1s
|
19년 전 | 2270 | |
| 355 | 20년 전 | 2736 | ||
| 354 | 20년 전 | 3019 | ||
| 353 | 20년 전 | 2784 | ||
| 352 |
|
20년 전 | 5763 | |
| 351 |
|
20년 전 | 2695 | |
| 350 |
|
20년 전 | 4281 | |
| 349 |
hwatta
|
20년 전 | 2174 | |
| 348 | 20년 전 | 7302 | ||
| 347 | 20년 전 | 2405 | ||
| 346 | 20년 전 | 3492 | ||
| 345 | 20년 전 | 4297 | ||
| 344 | 20년 전 | 2626 | ||
| 343 | 20년 전 | 3911 | ||
| 342 | 20년 전 | 3058 | ||
| 341 | 20년 전 | 4079 | ||
| 340 |
|
20년 전 | 5120 | |
| 339 |
|
20년 전 | 4224 | |
| 338 | 20년 전 | 5853 | ||
| 337 | 20년 전 | 2029 | ||
| 336 |
|
20년 전 | 3303 | |
| 335 |
|
20년 전 | 3529 | |
| 334 |
|
20년 전 | 2911 | |
| 333 |
hwatta
|
20년 전 | 2423 | |
| 332 | 20년 전 | 4645 | ||
| 331 | 20년 전 | 2259 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기