// Google Code Jam Round 1C 2013 A Consonants
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
//Google Code Jam
public class GoogleCode1 {
private static MyScanner in;
private static PrintStream out;
private static PrintStream sysout = System.out;
static int caseNum;
private static void solve() throws IOException
{
PreCompute();
int C = in.nextInt();
for (int i = 0; i < C; i++) {
caseNum = i + 1;
out.print("Case #" + caseNum + ": ");
solveCase();
}
}
private static void PreCompute() {
}
private static boolean isConsonant(char c) {
if ("aeiou".contains(Character.toString(c)))
return false;
return true;
}
private static void solveCase() throws IOException {
String s = in.nextString();
int N = in.nextInt();
int lastConsConsIdx = -1;
int nCons = 0;
long nv = 0;
for (int i = 0; i < s.length(); i++) {
if (isConsonant(s.charAt(i)))
nCons++;
else
nCons = 0;
if (nCons >= N) {
int firstCharIdx = i + 1 - N;
long nAfter = s.length() - i;
long nBefore = firstCharIdx - lastConsConsIdx;
if (firstCharIdx == 0)
nBefore = 1;
long cnt = nAfter * nBefore;
nv += cnt;
lastConsConsIdx = firstCharIdx;
}
}
out.println(nv);
}
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean usingFileForIO = true;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("E:\\zin.txt");
out = new PrintStream("E:\\zout.txt");
}
else {
in = new MyScanner();
out = System.out;
}
solve();
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
public String nextLine() throws IOException {
return inp.nextLine();
}
}
}
No comments:
Post a Comment