Thursday, June 6, 2013

Topcoder SRM 577 DIV 2 L1 EllysNewNickname

// Topcoder SRM 577 DIV 2 L1 EllysNewNickname

import java.util.*;
import java.math.*;

//rename the class name before submitting
public class EllysNewNickname {
    public static void main(String[] args) {
        EllysNewNickname obj = new EllysNewNickname();
        System.out.println(
                obj.getLength(
                        "a"
                        ));
    }

    public int getLength(String nickname) {
        int cnt = 0;
        boolean prevCharIsVowel = false;
        String vowels = "aeiouy";
        for (int i = 0; i < nickname.length(); i++) {
            boolean isVowel = vowels.contains(String.valueOf(nickname.charAt(i)));
            if (!prevCharIsVowel || !isVowel)
                cnt++;
            prevCharIsVowel = isVowel;
        }
        return cnt;
    }

}

No comments:

Post a Comment