Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class ggg {
- static FastReader in = new FastReader();
- static PrintWriter out = new PrintWriter(System.out);
- static char[] s = "welcome to code jam".toCharArray();
- static char[] line;
- static void solve(int tc) {
- try {
- line = in.nextLine().toCharArray();
- System.out.printf("Case #%d: %04d\n", tc, rec(0, 0));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }//tc
- static int rec(int a, int b) {
- if (b == s.length) {
- return 1;
- } else if (a == line.length) {
- return 0;
- }
- int tot = rec(a + 1, b);
- if (line[a] == s[b]) {
- tot += rec(a + 1, b + 1);
- }
- return tot;
- }
- static void tc() {
- try {
- int tc = Integer.parseInt(in.nextLine());
- for (int t = 0; t < tc; t++) {
- solve(t + 1);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }//tc
- public static void main(String[] args) {
- tc();
- // solve();
- out.flush();
- }
- static class FastReader {
- BufferedReader br;
- StringTokenizer st;
- FastReader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
- FastReader(File f) {
- try {
- br = new BufferedReader(new FileReader(f));
- } catch (FileNotFoundException x) {
- x.printStackTrace();
- }
- }
- String next() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- st = new StringTokenizer(br.readLine());
- }
- return st.nextToken();
- }
- String nextLine() throws IOException {
- return br.readLine();
- }
- int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- long nextLong() throws IOException {
- return Long.parseLong(next());
- }
- double nextDouble() throws IOException {
- return Double.parseDouble(next());
- }
- boolean hasNext() throws IOException {
- String s = br.readLine();
- if (s == null) {
- return false;
- }
- st = new StringTokenizer(s);
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement