Untitled
unknown
plain_text
10 months ago
1.2 kB
6
Indexable
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class FresherJavaTest {
public static void main(String[] args) {
String textInput = new Scanner(System.in).nextLine();
System.out.println(countVietnameseLetters(textInput));
}
public static String countVietnameseLetters(String input) {
List<String> telexTexts =List.of("aw", "aa", "dd", "ee", "oo", "ow", "w");
List<String> regexVNLetters = new ArrayList<>();
long count = 0;
for (int i = 0; i < input.length(); i++) {
// phải đối soát chứ cái tạo thành từ 1 ký tự trước
if (i + 1 <= input.length() && telexTexts.contains(input.substring(i, i + 1))) {
count++;
regexVNLetters.add(input.substring(i, i + 1));
} else if (i + 2 <= input.length() && telexTexts.contains(input.substring(i, i + 2))) {
count++;
regexVNLetters.add(input.substring(i, i + 2));
i++;
}
}
return count + " (" + String.join(", ", regexVNLetters) + ")";
}
}Editor is loading...
Leave a Comment