Re: [問題] 1-9位數不重複印出來 (D)
※ 引述《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
→
12/08 09:08, , 1F
12/08 09:08, 1F
→
12/08 09:09, , 2F
12/08 09:09, 2F
→
12/08 09:09, , 3F
12/08 09:09, 3F
→
12/08 10:49, , 4F
12/08 10:49, 4F
→
12/08 10:49, , 5F
12/08 10:49, 5F
→
12/08 10:50, , 6F
12/08 10:50, 6F
→
12/08 10:54, , 7F
12/08 10:54, 7F
→
12/08 11:45, , 8F
12/08 11:45, 8F
Programming 近期熱門文章
PTT數位生活區 即時熱門文章