Re: [問題] pattern產生器

看板C_and_CPP作者 ( )時間14年前 (2011/09/09 11:32), 編輯推噓4(404)
留言8則, 8人參與, 最新討論串2/2 (看更多)
之前看到一個神解法 一定要來分享一下 #include <cstdio> int main() { unsigned int input_set, subset; scanf("%u", &input_set); for (subset=input_set; subset!=0; subset=(subset-1)&input_set) printf("%x\n", subset); puts("0"); return 0; } ※ 引述《kuangyou ()》之銘言: : 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) : dev c++ : 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) : 問題(Question): : 輸入bit為1時,輸出該bit就要有0和一的組合,若輸入bit為0時,不CARE : 如輸入00001111 : 輸出 00000000,00000001,00000010,00000011...00001111 : 若輸入為1000001 : 輸出 00000000,00000001,10000000,10000001 : function prototype: : void pattern_gen(unsigned char inputmask,char *outputstr) : { : ...implement this... : } : main() : { : ...implement this... : } : 餵入的資料(Input): : 預期的正確結果(Expected Output): : 錯誤結果(Wrong Output): : 程式碼(Code):(請善用置底文網頁, 記得排版) : 補充說明(Supplement): : 小弟目前卡關當中... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.217.33.204

09/09 11:53, , 1F
大推(Y)
09/09 11:53, 1F

09/09 12:15, , 2F
推~
09/09 12:15, 2F

09/09 13:45, , 3F
有神快拜....Orz
09/09 13:45, 3F

09/09 14:45, , 4F
請全部都用 unsigned...
09/09 14:45, 4F

09/09 16:06, , 5F
~"~這裡到底有多少愛寫程式的阿,還有atoi.
09/09 16:06, 5F
※ 編輯: suhorng 來自: 61.217.33.204 (09/09 18:02) ※ 編輯: suhorng 來自: 61.217.33.204 (09/09 18:02)

09/09 23:25, , 6F
推~~ m(_ _)m
09/09 23:25, 6F

09/10 00:58, , 7F
書泓大師 <(__ __)>
09/10 00:58, 7F

09/10 09:13, , 8F
這是大陸人發明的~~不是我
09/10 09:13, 8F
文章代碼(AID): #1EQOZdkZ (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1EQOZdkZ (C_and_CPP)