爪哇8拉姆达,241 218 201 191 185 184(或161)个字符
因为您知道,Java也需要干表情符号。
import java.util.*;f->{int e,i=e=-1,c,l=f.length-1;while(++e<f[l].length&&f[l][e]!=45);List p=new Stack();l:for(;++i<3;){for(char[]r:f)if((c=r[e+i])==47|c==92)continue l;p.add(i);}return p;}
它返回一个ArrayList,一个HashSet,一个Stack,其中包含暴露在雨中的表情符号部分(索引从0开始)。整个东西都展开了:
import java.util.*;
public class Q82668 {
static List isEmojiDryRevE(char[][] fieldToCheck) {
int emojiStart, i = emojiStart = -1, j, rows = fieldToCheck.length - 1;
while (++emojiStart < fieldToCheck[rows].length && fieldToCheck[rows][emojiStart] != 45)
;
List parts = new Stack();
emojiLoop: for (; ++i < 3;) {
for (j = -1; ++j < rows;) {
if (fieldToCheck[j][emojiStart + i] > 46) {
// umbrella part found
continue emojiLoop;
}
}
// no umbrella part found
parts.add(i);
}
return parts;
}
}
更新
我做了一些基本的打高尔夫球。这包括将声明放在一起,与ascii值进行比较以节省一些字符并缩短循环。
感谢@ user902383指出我使用ArrayLists而不是List的转储错误。我用HashSets / Sets替换了ArrayLists / Lists,这节省了一些字符。也感谢他的技巧,在内部循环中使用foreach循环!通过该更改,我可以为最后一个网格行的索引创建一个变量,从而将其缩短一些。总共保存了17个字符!
@KevinCruijssen建议在初始化中删除泛型,我又走了一步:删除所有泛型。这样可以节省另外10个字符。
我从foreach循环切换回for循环。这使得跳过最后一行的比较成为可能,这反过来又使我可以缩短对ascii值的比较。在这种情况下,只有'/','\'和'_'的ascii值超过46。如果我们不检查最后一行,则可以使用a > 46 check
代替检查实际值。
再次感谢@ user902383,告诉我使用lambda并可以使用List + Stack而不是Set + HashSet来剃除另一个字符。
字符串返回版本
@ user902383指出,我可以改用数字创建字符串。这听起来很骗人,但其他人似乎是用这种方式解决的,因此这是使用String返回的较短版本:
f->{int e,i=e=-1,c,r=f.length-1;while(++e<f[r].length&&f[r][e]!=45);String p="";l:for(;++i<3;){for(char[]o:f)if((c=o[e+i])==47|c ==92)continue l;p+=i;}return p;}
取消高尔夫:
public class Q82668 {
public static String isEmojiDryRevD(char[][] fieldToCheck) {
int emojiStart, i = emojiStart = -1, c, rows = fieldToCheck.length - 1;
while (++emojiStart < fieldToCheck[rows].length && fieldToCheck[rows][emojiStart] != 45)
;
String parts = "";
emojiLoop: for (; ++i < 3;) {
for (char[] row : fieldToCheck) {
if ((c = row[emojiStart + i]) == 47 | c == 92) {
// umbrella part found
continue emojiLoop;
}
}
// no umbrella part found
parts += i;
}
return parts;
}
}
["_","-"]
。