Problem Link : http://www.codechef.com/problems/HOLES
Solution :
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/**
*
* @author XCoder
*/
class HolesInTheText {
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static PrintWriter pw = new PrintWriter(System.out);
public static int readIntLine() throws IOException {
return Integer.parseInt(br.readLine());
}
public static long readLongLine() throws IOException {
return Long.parseLong(br.readLine());
}
public static void main(String[] args) throws IOException {
int test = readIntLine();
while (test-- > 0) {
String str = br.readLine();
int holecount = 0;
for (char c : str.toCharArray()) {
if (c == 'A' || c == 'D' || c == 'O' || c == 'P' || c == 'Q' || c == 'R') {
holecount++;
} else if (c == 'B') {
holecount += 2;
}
}
pw.println(holecount);
}
pw.flush();
pw.close();
}
}
No comments:
Post a Comment