<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년 전 | 4088 | ||
| 429 | 19년 전 | 3284 | ||
| 428 | 19년 전 | 4118 | ||
| 427 | 19년 전 | 3462 | ||
| 426 | 19년 전 | 3093 | ||
| 425 | 19년 전 | 3389 | ||
| 424 | 19년 전 | 2430 | ||
| 423 | 19년 전 | 2841 | ||
| 422 | 19년 전 | 2333 | ||
| 421 | 19년 전 | 3700 | ||
| 420 | 19년 전 | 4723 | ||
| 419 | 19년 전 | 3775 | ||
| 418 |
|
19년 전 | 1723 | |
| 417 | 19년 전 | 2731 | ||
| 416 | 19년 전 | 2379 | ||
| 415 | 19년 전 | 2600 | ||
| 414 | 19년 전 | 4394 | ||
| 413 |
|
19년 전 | 2575 | |
| 412 | 19년 전 | 3025 | ||
| 411 |
|
19년 전 | 2977 | |
| 410 |
|
19년 전 | 3662 | |
| 409 |
|
19년 전 | 3621 | |
| 408 |
|
19년 전 | 1838 | |
| 407 | 19년 전 | 2207 | ||
| 406 | 19년 전 | 2766 | ||
| 405 | 19년 전 | 2433 | ||
| 404 | 19년 전 | 4291 | ||
| 403 | 19년 전 | 3288 | ||
| 402 |
NeoGenesis
|
19년 전 | 4076 | |
| 401 | 19년 전 | 2591 | ||
| 400 |
|
19년 전 | 2475 | |
| 399 | 19년 전 | 2941 | ||
| 398 | 19년 전 | 2474 | ||
| 397 | 19년 전 | 2774 | ||
| 396 | 19년 전 | 2460 | ||
| 395 | 19년 전 | 3165 | ||
| 394 | 19년 전 | 1697 | ||
| 393 | 19년 전 | 2978 | ||
| 392 | 19년 전 | 2240 | ||
| 391 | 19년 전 | 2171 | ||
| 390 | 19년 전 | 2264 | ||
| 389 | 19년 전 | 2628 | ||
| 388 | 19년 전 | 2119 | ||
| 387 | 19년 전 | 4463 | ||
| 386 |
|
19년 전 | 2670 | |
| 385 |
|
19년 전 | 2459 | |
| 384 | 19년 전 | 2974 | ||
| 383 | 19년 전 | 3035 | ||
| 382 | 19년 전 | 3088 | ||
| 381 |
|
19년 전 | 2623 | |
| 380 |
|
19년 전 | 3002 | |
| 379 | 19년 전 | 2537 | ||
| 378 | 19년 전 | 2194 | ||
| 377 | 19년 전 | 2769 | ||
| 376 | 19년 전 | 2463 | ||
| 375 |
|
19년 전 | 2548 | |
| 374 | 19년 전 | 3795 | ||
| 373 | 19년 전 | 3254 | ||
| 372 | 19년 전 | 4974 | ||
| 371 |
세은아빠2
|
19년 전 | 2401 | |
| 370 | 19년 전 | 4490 | ||
| 369 | 19년 전 | 3094 | ||
| 368 | 19년 전 | 2880 | ||
| 367 | 19년 전 | 3717 | ||
| 366 | 19년 전 | 2628 | ||
| 365 | 19년 전 | 3716 | ||
| 364 | 19년 전 | 3994 | ||
| 363 | 19년 전 | 3418 | ||
| 362 | 19년 전 | 3467 | ||
| 361 | 19년 전 | 4088 | ||
| 360 |
hwatta
|
19년 전 | 2346 | |
| 359 | 19년 전 | 5083 | ||
| 358 | 19년 전 | 3637 | ||
| 357 | 19년 전 | 2579 | ||
| 356 |
sdesign1s
|
19년 전 | 2260 | |
| 355 | 20년 전 | 2723 | ||
| 354 | 20년 전 | 3015 | ||
| 353 | 20년 전 | 2781 | ||
| 352 |
|
20년 전 | 5761 | |
| 351 |
|
20년 전 | 2690 | |
| 350 |
|
20년 전 | 4270 | |
| 349 |
hwatta
|
20년 전 | 2160 | |
| 348 | 20년 전 | 7297 | ||
| 347 | 20년 전 | 2403 | ||
| 346 | 20년 전 | 3483 | ||
| 345 | 20년 전 | 4289 | ||
| 344 | 20년 전 | 2613 | ||
| 343 | 20년 전 | 3904 | ||
| 342 | 20년 전 | 3050 | ||
| 341 | 20년 전 | 4075 | ||
| 340 |
|
20년 전 | 5106 | |
| 339 |
|
20년 전 | 4214 | |
| 338 | 20년 전 | 5840 | ||
| 337 | 20년 전 | 2021 | ||
| 336 |
|
20년 전 | 3295 | |
| 335 |
|
20년 전 | 3525 | |
| 334 |
|
20년 전 | 2908 | |
| 333 |
hwatta
|
20년 전 | 2417 | |
| 332 | 20년 전 | 4641 | ||
| 331 | 20년 전 | 2259 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기