爪哇8,346个 345 344 336 327字节
s->{int g=c(s+=" ","G"),u=c(s,"U"),w=c(s,"W"),x=c(s,"X"),f=c(s,"F")-u,h=c(s,"H")-g,v=c(s,"V")-f,o=c(s,"O")-u-w,i=c(s,"I")-f-x-g;return d(s=d(s=d(s=d(s=d(s=d(s=d(s=d(s=d("",o,1),w,2),h,3),u,4),f,5),x,6),v,7),g,8),n,9);}int c(String...s){return~-s[0].split(s[1]).length;}String d(String s,int i,int n){for(;i-->0;s+=n);return s;}
在这里尝试。
一般说明:
我看过字母表中每个字符的出现:
E 13357789
F 45
G 8
H 38
I 5689
N 1799
O 124
R 34
S 67
T 238
U 4
V 57
W 2
X 6
- 我首先计算了所有出现的单匹配字符:
G=8; U=4; W=2; X=6
。
- 然后出现所有两个匹配的字符,这些字符也匹配上述四个字符之一,我可以从它们的计数中减去
F=5; H=3
。
- 然后,我再次做了同样的事情
V=7
(减去F=5
)。
- 然后,剩下的所有三个匹配字符都相同:
O=1; N=9
。
- 但是由于中
N
有两次出现,因此我必须为的每次出现NINE
都做一个额外-1
的操作N
,所以我I=9
改用了(通过减去之前的三个匹配项而不是两个)。
代码说明:
s->{ // Method with String as parameter and return-type
int g=c(s+=" ","G"), // Amount of 8s (and append a space to `s` first, for the .split)
u=c(s,"U"), // Amount of 4s
w=c(s,"W"), // Amount of 2s
x=c(s,"X"), // Amount of 6s
f=c(s,"F")-u, // Amount of 5s
h=c(s,"H")-g, // Amount of 3s
v=c(s,"V")-f, // Amount of 7s
o=c(s,"O")-u-w, // Amount of 1s
i=c(s,"I")-f-x-g; // Amount of 9s
return d( // Return the result by:
s=d(
s=d(
s=d(
s=d(
s=d(
s=d(
s=d(
s=d("", // Making the input String `s` empty, since we no longer need it
o,1), // Append all 1s to `s`
w,2), // Append all 2s to `s`
h,3), // Append all 3s to `s`
u,4), // Append all 4s to `s`
f,5), // Append all 5s to `s`
x,6), // Append all 6s to `s`
v,7), // Append all 7s to `s`
g,8), // Append all 8s to `s`
i,9); // And then returning `s` + all 9s
} // End of method
int c(String...s){ // Separate method with String-varargs parameter and int return-type
// `s[0]` is the input-String
// `s[1]` is the character to check
return~-s[0].split(s[1]).length;
// Return the amount of times the character occurs in the String
} // End of separated method (1)
String d(String s,int i,int n){
// Separate method with String and two int parameters and String return-type
for(;i-->0; // Loop from the first integer-input down to 0
s+=n // And append the input-String with the second input-integer
); // End of loop
return s; // Return the resulting String
} // End of separated method (2)
"ONEWESTV" -> 27
(包括未实际出现的数字)