[問題] C語言問題 prefix mask(已解決)

看板C_and_CPP (C/C++)作者 (傑克)時間12年前 (2013/10/30 16:59), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
第一次在這邊發問問題,希望有人可以幫忙解答. http://acm.cs.nthu.edu.tw/problem.php?pid=1814 http://acm.cs.nthu.edu.tw/problem.php?pid=1815 目前在寫這兩題,有寫一點點了不知道問題在哪邊,希望有人能幫忙解決,感激不盡. *[36m餵入的資料(Input):*[m*[36m開發平台(Platform): C *[36m額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) *[m *[36m問題(Question):完全錯誤 *[36m餵入的資料(Input):*[m /* Input: 2 + * 2 - 5 3 * 3 4 + 5 - * - 9 3 2 1 Output: CASE 1: ((2*(5-3))+(3*4))=16 CASE 2: (5+(((9-3)*2)-1))=16 */ #include <stdio.h> #include <ctype.h> /* Uncomment the following #define before you submit the code to OJ. */ // #define ONLINE_JUDGE int calculate(void); int main(void) { int ncase, i; scanf("%d\n", &ncase); for (i=1; i<=ncase; i++) { printf("CASE %d:\n", i); printf("=%d\n", calculate()); while (getchar()!='\n'); } } int calculate() { int C; int X, Y, Z; while (1) { C = getchar(); if (isdigit(C) || C=='+' || C=='-' || C=='*' || C=='\n') break; } if (C=='\n') { return 0; } if (C=='+') { X=calculate(); Y=calculate(); Z=X+Y; return Z; } if (C=='-') { X=calculate(); Y=calculate(); Z=X-Y; return Z; } if (C=='*') { X=calculate(); Y=calculate(); Z=X*Y; return Z; } if (isdigit(C)) { ungetc(C, stdin); scanf("%d", &Z); printf("%d", Z); return Z; } } ------------------------------------------ /* Input: **--**-* -**-** Output: CASE 1: **00**0* **00**1* **01**0* **01**1* **10**0* **10**1* **11**0* **11**1* CASE 2: 0**0* 0**1* 1**0* 1**1*ss */ #include <stdio.h> #include <string.h> /* Uncomment the following #define before you submit the code to OJ. */ // #define ONLINE_JUDGE char bits[33]; char mask[33]; void showbit(int n); int main(void) { int ncase, i; ncase = 1; while (scanf("%32s", mask)!=EOF) { printf("CASE %d:\n", ncase); showbit(strlen(mask)); ncase++; for(i=0;i<33;i++) { bits[i]=0; mask[i]=0; } } return 0; } void showbit(int n) { int len; len = strlen(mask); if (n>0) { if(mask[n]=='*'){ bits[n]='*'; showbit(n-1); } else{ bits[n]='0'; showbit(n-1); bits[n]='1'; showbit(n-1); } } else { printf("%s\n", bits); } } ------------------------------------------------- 希望有人能告訴我答案是什麼或者問題出在哪,實在不知道怎麼修了. 謝謝各位大大們. 開發平台(Platform): C 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question):完全錯誤 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.143.179.132 ※ 編輯: jack7785 來自: 220.143.179.132 (10/30 17:01) ※ 編輯: jack7785 來自: 220.143.179.132 (10/30 17:07)

10/30 17:19, , 1F
首先你可以先看看置底貼程式碼。
10/30 17:19, 1F

10/30 17:39, , 2F
第一次在這版發文 想自D發現無法 囧 太亂了對不起大家
10/30 17:39, 2F
文章代碼(AID): #1ISCfVVI (C_and_CPP)
文章代碼(AID): #1ISCfVVI (C_and_CPP)