看板 Programming 關於我們 聯絡資訊
※ 引述《mikemagic88 (Mikemagic88)》之銘言: : 使用者輸入1 印1-9 : 使用者輸入2 印1-98 (11, 22, 33等重複的不印) : 使用者輸入3 印1-987 (121, 988, 667等有重複的不印) import std.stdio; import std.string; import std.conv; import std.math; import std.regex; void main() { write("\nInput something punk> "); auto input = strip(stdin.readln()); int level = to!int(input); level = (level>=10)?10: (level<=0)?0:level; if(level==0) return; else write(1); for(int i=2,max_i=pow(10,level);i<max_i;i++) { string si = to!string(i); int[string] aa; for(int j=0;j<=9;j++) { aa[to!string(j)]=0; } int is_found=0; for(int j=0,max_j=to!int(countchars(si,"0123456789"));j<max_j;j++) { if( aa[ to!string(si[j]) ] !=0) { is_found=1; break; } else { aa[ to!string(si[j]) ]=1; } } if(is_found == 0) { write(", "); write(i); } } writeln(""); } (dmd-2.072.1)[root@3wa d]# rdmd mycode.d Input something punk> 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 (dmd-2.072.1)[root@3wa d]# -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.233.81.220 ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1481115189.A.151.html ※ 編輯: shadowjohn (36.233.81.220), 12/07/2016 20:54:26
shadowjohn: :( D 的re match試半天(.).*\1 140.134.48.253 12/08 09:08
shadowjohn: 但都只有生效一次,希望有好心人幫忙 140.134.48.253 12/08 09:09
shadowjohn: matchAll跟 ,"g" 也都試了~ :~ 140.134.48.253 12/08 09:09
Neisseria: 有些冷門語言的 regex engine 怪怪的 125.227.36.83 12/08 10:49
Neisseria: 像我也發現 Rust 內建的 regex 不好用 125.227.36.83 12/08 10:49
Neisseria: 後來就改用 pcre,才比較順手 125.227.36.83 12/08 10:50
Neisseria: 如果有問題,換個 regex engine 比較快 125.227.36.83 12/08 10:54
shadowjohn: 原來如此,晚點再試一下~謝啦^_^~~ 140.134.48.253 12/08 11:45