Java implementation of vampire digital
•
Java
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">public@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ <span style="color: #0000ff;">static@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ <span style="color: #0000ff;">void@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;"> main(String[] arg) {
String[] ar_str1,ar_str2;
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">int@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ sum = <span style="color: #800080;">0@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">;
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">int@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ <span style="color: #0000ff;">from@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">;
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">int@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;"> to;
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">int@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;"> i_val;
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">int@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ count = <span style="color: #800080;">0@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">;
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #008000;">//@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #008000;"> 双重循环穷举 @H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@
<span style="color: #0000ff;">for@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ (<span style="color: #0000ff;">int@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ i = <span style="color: #800080;">10@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@; i < <span style="color: #800080;">100@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@; i++<span style="color: #000000;">) {
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #008000;">//@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #008000;"> j=i+1避免重复 @H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@
<span style="color: #0000ff;">from@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ = Math.max(<span style="color: #800080;">1000@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ / i,i + <span style="color: #800080;">1@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">);
to @H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@= Math.min(<span style="color: #800080;">10000@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ / i,<span style="color: #800080;">100@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">);
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">for@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ (<span style="color: #0000ff;">int@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ j = <span style="color: #0000ff;">from@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@; j < to; j++<span style="color: #000000;">) {
i_val @H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@= i *<span style="color: #000000;"> j;
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@
<span style="color: #0000ff;">if@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ (i_val % <span style="color: #800080;">100@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ == <span style="color: #800080;">0@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ || (i_val - i - j) % <span style="color: #800080;">9@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ != <span style="color: #800080;">0@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">) {
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">continue@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">;
}
count@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@++<span style="color: #000000;">;
ar_str1 @H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@= String.valueOf(i_val).split(<span style="color: #800000;">""@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">);
ar_str2 @H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@= (String.valueOf(i) + String.valueOf(j)).split(<span style="color: #800000;">""@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">);
Arrays<a href="https://www.jb51.cc/tag/so/" target="_blank" class="keywords">.so</a>rt(ar_str1);
Arrays<a href="https://www.jb51.cc/tag/so/" target="_blank" class="keywords">.so</a>rt(ar_str2);
@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">if@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ (Arrays.equals(ar_str1,ar_str2)) {<span style="color: #008000;">//@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #008000;"> 排序后比较,为真则找到一组 @H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@
sum++<span style="color: #000000;">;
Sy<a href="https://www.jb51.cc/tag/stem/" target="_blank" class="keywords">stem</a>.@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">out@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@.println(<span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">第@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ + sum + <span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">组: @H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ + i + <span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">*@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ + j + <span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">=@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ +<span style="color: #000000;"> i_val);
}
}
}
Sy<a href="https://www.jb51.cc/tag/stem/" target="_blank" class="keywords">stem</a>.@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">out@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@.println(<span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">共找到@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@ + sum + <span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">组吸血鬼数@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #800000;">"@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">);
Sy<a href="https://www.jb51.cc/tag/stem/" target="_blank" class="keywords">stem</a>.@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #0000ff;">out@H_<a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a>_1@<span style="color: #000000;">.println(count);
}
}@H_ 502_ 1@
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码