<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="" />
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 330 |
prosper
|
20년 전 | 2253 | |
| 329 |
prosper
|
20년 전 | 1864 | |
| 328 |
prosper
|
20년 전 | 1677 | |
| 327 | 20년 전 | 3751 | ||
| 326 | 20년 전 | 4833 | ||
| 325 |
hwatta
|
20년 전 | 2460 | |
| 324 |
|
20년 전 | 3129 | |
| 323 | 20년 전 | 5841 | ||
| 322 |
hwatta
|
20년 전 | 2828 | |
| 321 |
hwatta
|
20년 전 | 2304 | |
| 320 |
yesmoa
|
20년 전 | 4560 | |
| 319 | 20년 전 | 2665 | ||
| 318 | 20년 전 | 2229 | ||
| 317 |
kyodon
|
20년 전 | 2755 | |
| 316 | 20년 전 | 2564 | ||
| 315 |
|
20년 전 | 2874 | |
| 314 |
|
20년 전 | 3323 | |
| 313 |
|
20년 전 | 2632 | |
| 312 |
yesmoa
|
20년 전 | 4703 | |
| 311 | 20년 전 | 3256 | ||
| 310 |
홀로남은자
|
20년 전 | 4547 | |
| 309 | 20년 전 | 3001 | ||
| 308 | 20년 전 | 4115 | ||
| 307 | 20년 전 | 4347 | ||
| 306 | 20년 전 | 7023 | ||
| 305 | 20년 전 | 3861 | ||
| 304 | 20년 전 | 2751 | ||
| 303 |
크리스탈처럼
|
20년 전 | 4384 | |
| 302 | 20년 전 | 2197 | ||
| 301 |
|
20년 전 | 4314 | |
| 300 | 20년 전 | 3783 | ||
| 299 | 20년 전 | 2590 | ||
| 298 | 20년 전 | 4814 | ||
| 297 |
|
20년 전 | 2519 | |
| 296 | 20년 전 | 4513 | ||
| 295 | 20년 전 | 3559 | ||
| 294 | 20년 전 | 3584 | ||
| 293 | 20년 전 | 3807 | ||
| 292 | 20년 전 | 3197 | ||
| 291 |
yesmoa
|
20년 전 | 5927 | |
| 290 | 20년 전 | 2931 | ||
| 289 | 20년 전 | 5835 | ||
| 288 |
|
20년 전 | 2365 | |
| 287 |
|
20년 전 | 1781 | |
| 286 |
|
20년 전 | 2135 | |
| 285 |
|
20년 전 | 3529 | |
| 284 |
|
20년 전 | 2026 | |
| 283 |
|
20년 전 | 4397 | |
| 282 | 20년 전 | 3379 | ||
| 281 |
|
20년 전 | 2198 | |
| 280 |
|
20년 전 | 7792 | |
| 279 | 20년 전 | 5538 | ||
| 278 | 20년 전 | 2982 | ||
| 277 |
|
20년 전 | 5563 | |
| 276 | 20년 전 | 2350 | ||
| 275 | 20년 전 | 2595 | ||
| 274 | 20년 전 | 2370 | ||
| 273 | 20년 전 | 2206 | ||
| 272 | 20년 전 | 2136 | ||
| 271 | 20년 전 | 2596 | ||
| 270 | 20년 전 | 2607 | ||
| 269 | 20년 전 | 2473 | ||
| 268 | 20년 전 | 2671 | ||
| 267 | 20년 전 | 2354 | ||
| 266 | 20년 전 | 2557 | ||
| 265 | 20년 전 | 3492 | ||
| 264 |
|
20년 전 | 5348 | |
| 263 |
|
20년 전 | 3718 | |
| 262 | 20년 전 | 3166 | ||
| 261 |
허저비
|
20년 전 | 5914 | |
| 260 |
|
20년 전 | 5708 | |
| 259 | 20년 전 | 4130 | ||
| 258 | 20년 전 | 2373 | ||
| 257 | 20년 전 | 3177 | ||
| 256 | 20년 전 | 1895 | ||
| 255 | 20년 전 | 1560 | ||
| 254 | 20년 전 | 3135 | ||
| 253 | 20년 전 | 3541 | ||
| 252 | 20년 전 | 5112 | ||
| 251 | 20년 전 | 5796 | ||
| 250 | 20년 전 | 3668 | ||
| 249 | 20년 전 | 5010 | ||
| 248 | 20년 전 | 3275 | ||
| 247 | 20년 전 | 3627 | ||
| 246 |
|
20년 전 | 7941 | |
| 245 |
|
20년 전 | 5895 | |
| 244 | 20년 전 | 4479 | ||
| 243 |
|
20년 전 | 4041 | |
| 242 | 20년 전 | 2773 | ||
| 241 | 20년 전 | 2713 | ||
| 240 | 20년 전 | 2352 | ||
| 239 | 20년 전 | 1649 | ||
| 238 |
아우겐나이스
|
20년 전 | 2255 | |
| 237 |
email
|
20년 전 | 3677 | |
| 236 | 20년 전 | 4143 | ||
| 235 | 20년 전 | 10458 | ||
| 234 | 20년 전 | 5056 | ||
| 233 | 20년 전 | 3361 | ||
| 232 | 20년 전 | 3193 | ||
| 231 | 20년 전 | 3830 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기