Re: [問題] 1-9位數不重複印出來 (C++ error)

看板Programming作者 (LCamel)時間7年前 (2016/12/13 02:52), 7年前編輯推噓3(303)
留言6則, 6人參與, 最新討論串1/1
※ 引述《mikemagic88 (Mikemagic88)》之銘言: : 使用者輸入1 印1-9 : 使用者輸入2 印1-98 (11, 22, 33等重複的不印) : 使用者輸入3 印1-987 (121, 988, 667等有重複的不印) 用 compile 的 error message 來印: (好讀版 https://gist.github.com/LCamel/9f5305d53d11dfe96d73ebda7c23048e ) template <int i> struct Print { enum : int { v = (void) i // die! };}; template <int i, bool b> struct Test { enum : int { v = 42 };}; template <int i > struct Test<i, false> { enum : int { v = 42 };}; template <int i > struct Test<i, true> { enum : int { v = Print<i>::v };}; template <int i, int d2, int d1, int d0> struct Digits { enum : int { v = Test<i, d2 == 0 ? (d1 == 0 || d1 != d0) : d2 != d1 && d1 != d0 && d0 != d2 >::v };}; template <int i> struct Loop { enum : int { p = Digits<i, i / 100, (i / 10) % 10, i % 10>::v, v = Loop<i + 1>::v };}; template <> struct Loop<1000> { enum : int { v = 42 };}; Loop<1> go; 列印方法: g++ -std=c++0x -ftemplate-depth=1001 a.cpp 2>&1 | grep -oP '(?<=Print<)\d+' (應該可以再短 不過先湊到能跑...) LCamel -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.229.105.20 ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1481568735.A.6D7.html

12/13 03:23, , 1F
笑惹.... XD
12/13 03:23, 1F

12/13 13:13, , 2F
強,template meta programming
12/13 13:13, 2F
※ 編輯: LCamel (114.45.180.161), 12/14/2016 08:38:47

12/15 03:26, , 3F
XDDDDDD太會了吧
12/15 03:26, 3F

12/15 10:22, , 4F
本串最佳 XDDD
12/15 10:22, 4F

12/15 23:43, , 5F
讚wwww
12/15 23:43, 5F

12/18 17:36, , 6F
呃 後來發現位數寫死了 還請多包涵
12/18 17:36, 6F
文章代碼(AID): #1OJl7VRN (Programming)