Re: [問題] 這個演算法要怎麼寫出來?

看板C_and_CPP (C/C++)作者 (打不贏怪兵器不好)時間16年前 (2009/06/05 13:51), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
本來想說可以用strtok 可是他會把delim刪掉... #include <stdio.h> #include <string.h> #include <stdlib.h> int main(){ char * in=malloc(sizeof(char)*100); printf("Enter your string:"); scanf("%s",in); char * endptr; double d=strtod(in,&endptr); do{ printf("%f,%c\n",d,*endptr); endptr++ ; d=strtod(endptr,&endptr); }while(*endptr!='\0'); printf("%f\n",d); return 0; } Enter your string:1+(2+3+(4+5)) 1.000000,+ 0.000000,( 2.000000,+ 3.000000,+ 0.000000,( 4.000000,+ 5.000000,) 0.000000,) 0.000000 會變成這樣, ( )都拆出來了, 就去判斷一下遇到 ( 的時候那個 0.000000 的數字應該改成甚麼就知道了 要是我大概會改成這樣吧 1+1(2+3+1(4+5)) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.123.102.254
文章代碼(AID): #1AAB9hvu (C_and_CPP)
文章代碼(AID): #1AAB9hvu (C_and_CPP)