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