检查字符串有字母表中的所有字母 [英] Check if string has all the letters of the alphabet
本文介绍了检查字符串有字母表中的所有字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是检查所有的字母给定的字符串中最好的逻辑。
What would be the best logic to check all the letters in a given string.
如果所有26个字母都在提供的字符串可用,我要检查并执行这样欢声笑语。例如。我的包箱五打酒水罐。
If all the 26 letters are available in the provided string, I want to check that and perform so ops. eg. Pack my box with five dozen liquor jugs.
- 会使用散列是有用的?
- 或使用位图?或任何其他方式?
顺便说一句我的code将在Java中。
BTW my code would be in Java.
推荐答案
尚未完全优化的:
public static void main(String... a) {
String s = "Pack my box with five dozen liquor jugs.";
int i=0;
for(char c : s.toCharArray()) {
int x = Character.toUpperCase(c);
if (x >= 'A' && x <= 'Z') {
i |= 1 << (x - 'A');
}
}
if (i == (i | ((1 << (1 + 'Z' - 'A')) - 1))) {
System.out.println("ok");
}
}
这篇关于检查字符串有字母表中的所有字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文