Skip to main content
added 20 characters in body
Source Link
IEatBagels
  • 12.7k
  • 3
  • 48
  • 99
public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String word = "aeiuzzz";
    final int inputLength = word.length();

    if (inputLength >= 10000) {
        System.err.println("The size of the string can not be greater than 10,000");
        System.exit(1);
    }

    HashSet<Character> vowels = initializeVowels();
    short found = 0;

    for (final char c : word.toCharArray()) {
        if (vowels.contains(c)) {
//remove returns true if the value was removed! So it's found only found++;once
           if (vowels.remove(c);) //To{
 avoid false positives.         found++;
        }
    }        

    String result = (found == vowels.size()) ? "yes" : "no";

    System.out.println(result);
}

private static HashSet<Character> initializeVowels() {
    HashSet<Character> vowels = new HashSet<Character>();
    vowels.add('a');
    vowels.add('e');
    vowels.add('i');
    vowels.add('o');
    vowels.add('u');

    return vowels;
}
public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String word = "aeiuzzz";
    final int inputLength = word.length();

    if (inputLength >= 10000) {
        System.err.println("The size of the string can not be greater than 10,000");
        System.exit(1);
    }

    HashSet<Character> vowels = initializeVowels();
    short found = 0;

    for (final char c : word.toCharArray()) {
        if (vowels.contains(c)) {
            found++;
            vowels.remove(c); //To avoid false positives.
        }
    }        

    String result = (found == vowels.size()) ? "yes" : "no";

    System.out.println(result);
}

private static HashSet<Character> initializeVowels() {
    HashSet<Character> vowels = new HashSet<Character>();
    vowels.add('a');
    vowels.add('e');
    vowels.add('i');
    vowels.add('o');
    vowels.add('u');

    return vowels;
}
public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String word = "aeiuzzz";
    final int inputLength = word.length();

    if (inputLength >= 10000) {
        System.err.println("The size of the string can not be greater than 10,000");
        System.exit(1);
    }

    HashSet<Character> vowels = initializeVowels();
    short found = 0;

    for (final char c : word.toCharArray()) {
        //remove returns true if the value was removed! So it's found only once
        if (vowels.remove(c)) {
            found++;
        }
    }        

    String result = (found == vowels.size()) ? "yes" : "no";

    System.out.println(result);
}

private static HashSet<Character> initializeVowels() {
    HashSet<Character> vowels = new HashSet<Character>();
    vowels.add('a');
    vowels.add('e');
    vowels.add('i');
    vowels.add('o');
    vowels.add('u');

    return vowels;
}
added 186 characters in body
Source Link
IEatBagels
  • 12.7k
  • 3
  • 48
  • 99
public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String word = "aeiuzzz";
    final int inputLength = word.length();

    if (inputLength >= 10000) {
        System.err.println("The size of the string can not be greater than 10,000");
        System.exit(1);
    }

    HashSet<Character> vowels = initializeVowels();
    short found = 0;

    for (final char c : word.toCharArray()) {
        if (vowels.contains(c)) {
            found++;
            vowels.remove(c); //To avoid false positives.
        }
    }        

    String result = (found == vowels.size()) ? "yes" : "no";

    System.out.println(result);
}

private static HashSet<Character> initializeVowels() {
    HashSet<Character> vowels = new HashSet<Character>();
    vowels.add('a');
    vowels.add('e');
    vowels.add('i');
    vowels.add('o');
    vowels.add('u');

    return vowels;
}

In theory, this algorithm is more efficient and extensible. Though, considering that vowels is very small (5 elements), there probably wouldn't be a big difference. Still, it's good to see how it should be done. Though, consider vowels don't change very often, using a solution like @Eric's one will probably be faster.

public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String word = "aeiuzzz";
    final int inputLength = word.length();

    if (inputLength >= 10000) {
        System.err.println("The size of the string can not be greater than 10,000");
        System.exit(1);
    }

    HashSet<Character> vowels = initializeVowels();
    short found = 0;

    for (final char c : word.toCharArray()) {
        if (vowels.contains(c)) {
            found++;
        }
    }        

    String result = (found == vowels.size()) ? "yes" : "no";

    System.out.println(result);
}

private static HashSet<Character> initializeVowels() {
    HashSet<Character> vowels = new HashSet<Character>();
    vowels.add('a');
    vowels.add('e');
    vowels.add('i');
    vowels.add('o');
    vowels.add('u');

    return vowels;
}

In theory, this algorithm is more efficient. Though, considering that vowels is very small (5 elements), there probably wouldn't be a big difference. Still, it's good to see how it should be done.

public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String word = "aeiuzzz";
    final int inputLength = word.length();

    if (inputLength >= 10000) {
        System.err.println("The size of the string can not be greater than 10,000");
        System.exit(1);
    }

    HashSet<Character> vowels = initializeVowels();
    short found = 0;

    for (final char c : word.toCharArray()) {
        if (vowels.contains(c)) {
            found++;
            vowels.remove(c); //To avoid false positives.
        }
    }        

    String result = (found == vowels.size()) ? "yes" : "no";

    System.out.println(result);
}

private static HashSet<Character> initializeVowels() {
    HashSet<Character> vowels = new HashSet<Character>();
    vowels.add('a');
    vowels.add('e');
    vowels.add('i');
    vowels.add('o');
    vowels.add('u');

    return vowels;
}

In theory, this algorithm is more efficient and extensible. Though, considering that vowels is very small (5 elements), there probably wouldn't be a big difference. Still, it's good to see how it should be done. Though, consider vowels don't change very often, using a solution like @Eric's one will probably be faster.

fixed Markdown formatting.
Source Link
h.j.k.
  • 19.4k
  • 3
  • 37
  • 93

public static void main(String[] args) throws IOException {

public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String word = "aeiuzzz";
    final int inputLength = word.length();

    if (inputLength >= 10000) {
        System.err.println("The size of the string can not be greater than 10,000");
        System.exit(1);
    }

    HashSet<Character> vowels = initializeVowels();
    short found = 0;

    for (final char c : word.toCharArray()) {
        if (vowels.contains(c)) {
            found++;
        }
    }        

    String result = (found == vowels.size()) ? "yes" : "no";

    System.out.println(result);
}

private static HashSet<Character> initializeVowels() {
    HashSet<Character> vowels = new HashSet<Character>();
    vowels.add('a');
    vowels.add('e');
    vowels.add('i');
    vowels.add('o');
    vowels.add('u');

    return vowels;
}

public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String word = "aeiuzzz";
    final int inputLength = word.length();

    if (inputLength >= 10000) {
        System.err.println("The size of the string can not be greater than 10,000");
        System.exit(1);
    }

    HashSet<Character> vowels = initializeVowels();
    short found = 0;

    for (final char c : word.toCharArray()) {
        if (vowels.contains(c)) {
            found++;
        }
    }        

    String result = (found == vowels.size()) ? "yes" : "no";

    System.out.println(result);
}

private static HashSet<Character> initializeVowels() {
    HashSet<Character> vowels = new HashSet<Character>();
    vowels.add('a');
    vowels.add('e');
    vowels.add('i');
    vowels.add('o');
    vowels.add('u');

    return vowels;
}
public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String word = "aeiuzzz";
    final int inputLength = word.length();

    if (inputLength >= 10000) {
        System.err.println("The size of the string can not be greater than 10,000");
        System.exit(1);
    }

    HashSet<Character> vowels = initializeVowels();
    short found = 0;

    for (final char c : word.toCharArray()) {
        if (vowels.contains(c)) {
            found++;
        }
    }        

    String result = (found == vowels.size()) ? "yes" : "no";

    System.out.println(result);
}

private static HashSet<Character> initializeVowels() {
    HashSet<Character> vowels = new HashSet<Character>();
    vowels.add('a');
    vowels.add('e');
    vowels.add('i');
    vowels.add('o');
    vowels.add('u');

    return vowels;
}
Source Link
IEatBagels
  • 12.7k
  • 3
  • 48
  • 99
Loading