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

作者: shadowjohn (轉角遇到愛)   2016-12-07 20:53:05
※ 引述《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)[[email protected]/*
繼續閱讀

Links booklink

Contact Us: admin [ a t ] ucptt.com