[問題] 判斷輸出問題

看板C_and_CPP作者 (天生我材)時間9年前 (2014/08/16 18:59), 編輯推噓4(401)
留言5則, 5人參與, 最新討論串1/3 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Dev-C++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) ....先前一些零粹的code就不PO上來了 以下是我要判斷的條件輸出程式碼 int q[5]; for(c=0,d=0;c<5;c++){ for(e=0;e<5;e++){ if(a[c]!=a[e]){ q[c]=a[c]; } for(int j=0;j<5;j++){ printf("%d",q[j]); } } } } 比如說輸入一串數字 1 2 3 4 5 1 2 3 5 6 輸出會是 1 2 3 4 5 6 意思把前面重複的數字刪除 我做法是每往下一個,判斷後重頭再跑一次判斷,額外存入另一個變數內 最後依序輸出不知道這樣做法哪裡錯誤了~"~一直弄不出來 求解~.~thanks 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.171.35.28 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1408186775.A.6D3.html

08/16 20:00, , 1F
這讓我想到String Matching: Knuth-Morris-Pratt
08/16 20:00, 1F

08/16 21:33, , 2F
因該不用這麼複雜,沒用到什麼資料結構的東西0.0
08/16 21:33, 2F

08/16 21:52, , 3F
08/16 21:52, 3F

08/16 22:44, , 4F
KMP已經夠簡單了....
08/16 22:44, 4F

08/17 03:29, , 5F
直接用 set?
08/17 03:29, 5F
文章代碼(AID): #1JxpcNRJ (C_and_CPP)
文章代碼(AID): #1JxpcNRJ (C_and_CPP)