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

看板Programming作者 (轉角遇到愛)時間7年前 (2016/11/23 13:34), 7年前編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
※ 引述《mikemagic88 (Mikemagic88)》之銘言: : 使用者輸入1 印1-9 : 使用者輸入2 印1-98 (11, 22, 33等重複的不印) : 使用者輸入3 印1-987 (121, 988, 667等有重複的不印) <?php $c = (int)readline("Enter a number: "); for($i=1,$max_i=10**$c;$i<$max_i;$i++) if($i==implode(array_values(array_unique(str_split($i))))) echo ($i==1)?$i:", {$i}"; 或 <?php $c = (int)readline("Enter a number: "); for($i=1,$max_i=10**$c;$i<$max_i;$i++){ if(!preg_match("/(1.*1|2.*2|3.*3|4.*4|5.*5|6.*6|7.*7|8.*8|9.*9|0.*0)/",$i)) echo ($i==1)?$i:", {$i}"; } [root@3wa 1_N9]# php go.php Enter a number: 2 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.134.48.253 ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1479879258.A.5AC.html ※ 編輯: shadowjohn (140.134.48.253), 11/23/2016 16:17:19

11/28 10:12, , 1F
preg_match('/(\d).*\1/',$i)
11/28 10:12, 1F

11/28 21:45, , 2F
3Q~
11/28 21:45, 2F
文章代碼(AID): #1ODIfQMi (Programming)