<div class="cnblogs_code">
</span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> main(String[] arg) {
String[] ar_str1,ar_str2;
</span><span style="color: #0000ff;">int</span> sum = <span style="color: #800080;">0</span><span style="color: #000000;">;
</span><span style="color: #0000ff;">int</span> <span style="color: #0000ff;">from</span><span style="color: #000000;">;
</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> to;
</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> i_val;
</span><span style="color: #0000ff;">int</span> count = <span style="color: #800080;">0</span><span style="color: #000000;">;
</span><span style="color: #008000;">//</span><span style="color: #008000;"> 双重循环穷举 </span>
<span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">int</span> i = <span style="color: #800080;">10</span>; i < <span style="color: #800080;">100</span>; i++<span style="color: #000000;">) {
</span><span style="color: #008000;">//</span><span style="color: #008000;"> j=i+1避免重复 </span>
<span style="color: #0000ff;">from</span> = Math.max(<span style="color: #800080;">1000</span> / i,i + <span style="color: #800080;">1</span><span style="color: #000000;">);
to </span>= Math.min(<span style="color: #800080;">10000</span> / i,<span style="color: #800080;">100</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">int</span> j = <span style="color: #0000ff;">from</span>; j < to; j++<span style="color: #000000;">) {
i_val </span>= i *<span style="color: #000000;"> j;
</span>
<span style="color: #0000ff;">if</span> (i_val % <span style="color: #800080;">100</span> == <span style="color: #800080;">0</span> || (i_val - i - j) % <span style="color: #800080;">9</span> != <span style="color: #800080;">0</span><span style="color: #000000;">) {
</span><span style="color: #0000ff;">continue</span><span style="color: #000000;">;
}
count</span>++<span style="color: #000000;">;
ar_str1 </span>= String.valueOf(i_val).split(<span style="color: #800000;">""</span><span style="color: #000000;">);
ar_str2 </span>= (String.valueOf(i) + String.valueOf(j)).split(<span style="color: #800000;">""</span><span style="color: #000000;">);
Arrays.sort(ar_str1);
Arrays.sort(ar_str2);
</span><span style="color: #0000ff;">if</span> (Arrays.equals(ar_str1,ar_str2)) {<span style="color: #008000;">//</span><span style="color: #008000;"> 排序后比较,为真则找到一组 </span>
sum++<span style="color: #000000;">;
System.</span><span style="color: #0000ff;">out</span>.println(<span style="color: #800000;">"</span><span style="color: #800000;">第</span><span style="color: #800000;">"</span> + sum + <span style="color: #800000;">"</span><span style="color: #800000;">组: </span><span style="color: #800000;">"</span> + i + <span style="color: #800000;">"</span><span style="color: #800000;">*</span><span style="color: #800000;">"</span> + j + <span style="color: #800000;">"</span><span style="color: #800000;">=</span><span style="color: #800000;">"</span> +<span style="color: #000000;"> i_val);
}
}
}
System.</span><span style="color: #0000ff;">out</span>.println(<span style="color: #800000;">"</span><span style="color: #800000;">共找到</span><span style="color: #800000;">"</span> + sum + <span style="color: #800000;">"</span><span style="color: #800000;">组吸血鬼数</span><span style="color: #800000;">"</span><span style="color: #000000;">);
System.</span><span style="color: #0000ff;">out</span><span style="color: #000000;">.println(count);
}
}