Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
1
Indexable
Never
public static int countVietnameseLetters(String str) {
        int count = 0;
        int n = str.length();

        if (str.charAt(n - 1) == 'w' && str.charAt(n - 2) != 'a' && str.charAt(n - 2) != 'o')
            count++;

        int i = 0;
        while (i < n - 1) {
            if (str.charAt(i) == 'a' && str.charAt(i + 1) == 'w') {
                count++;
                i += 2;
                continue;
            }

            if (str.charAt(i) == 'a' && str.charAt(i + 1) == 'a') {
                count++;
                i += 2;
                continue;
            }

            if (str.charAt(i) == 'd' && str.charAt(i + 1) == 'd') {
                count++;
                i += 2;
                continue;
            }

            if (str.charAt(i) == 'e' && str.charAt(i + 1) == 'e') {
                count++;
                i += 2;
                continue;
            }

            if (str.charAt(i) == 'o' && str.charAt(i + 1) == 'o') {
                count++;
                i += 2;
                continue;
            }

            if (str.charAt(i) == 'o' && str.charAt(i + 1) == 'w') {
                count++;
                i += 2;
                continue;
            }

            if (str.charAt(i) == 'w') {
                count++;
                i++;
                continue;
            }

            i++;
        }
        return count;
    }