- 993 名前:989 mailto:sage [02/09/29 21:05]
- 俺はlispを知らないので、代わりにlisp風?ミニ電卓を作ってみた。
"(* (+ 2 3) 4)" みたいな計算ができる。 貧弱な上短くする余地もまだまだある、つーか手抜きだが、その辺は好きに弄ってくれ。 #include<stdio.h> char s[999],*p=s;a(void){int r=0;if(*p=='('){char c=*++p;++p;while(*p==32)++p; if(c=='+')r=a()+a();else if(c=='-')r=a()-a();else if(c=='*')r=a()*a();else if( c=='/')r=a()/a();else if(c=='%')r=a()%a();else if(c=='p'){r=a();printf("%d\n", r);}++p;}else do{r=r*10+*(p++)-'0';}while(*p!=32&&*p!=0&&*p!=')');while(*p==32 )++p;return r;}main(){gets(s);printf("%d\n",a());return 0;}
|

|