本题的 Large dataset 本人尚未解决。

https://code.google.com/codejam/contest/90101/dashboard#s=p2

Problem

So you've registered. We sent you a welcoming email, to welcome you to code jam. But it's possible that you still don't feel welcomed to code jam. That's why we decided to name a problem "welcome to code jam." After solving this problem, we hope that you'll feel very welcome. Very welcome, that is, to code jam.

If you read the previous paragraph, you're probably wondering why it's there. But if you read it very carefully, you might notice that we have written the words "welcome to code jam" several times: 400263727 times in total. After all, it's easy to look through the paragraph and find a 'w'; then find an 'e' later in the paragraph; then find an 'l' after that, and so on. Your task is to write a program that can take any text and print out how many times that text contains the phrase "welcome to code jam".

To be more precise, given a text string, you are to determine how many times the string "welcome to code jam" appears as a sub-sequence of that string. In other words, find a sequence s of increasing indices into the input string such that the concatenation of input[s[0]], input[s[1]], ..., input[s[18]] is the string "welcome to code jam".

The result of your calculation might be huge, so for convenience we would only like you to find the last 4 digits.

Input

The first line of input gives the number of test cases, N. The next N lines of input contain one test case each. Each test case is a single line of text, containing only lower-case letters and spaces. No line will start with a space, and no line will end with a space.

Output

For each test case, "Case #x: dddd", where x is the case number, and dddd is the last four digits of the answer. If the answer has fewer than 4 digits, please add zeroes at the front of your answer to make it exactly 4 digits long.

Limits

1 ≤ N ≤ 100

Small dataset

Each line will be no longer than 30 characters.

Large dataset

Each line will be no longer than 500 characters.

Sample

Input 
 
Output 
 
3
elcomew elcome to code jam
wweellccoommee to code qps jam
welcome to codejam

Case #1: 0001
Case #2: 0256
Case #3: 0000

Solution (For small dataset only):

string welcome = string("welcome to code jam");
int tc = ;
int fo[], cp[];
string input;
int inlen; void radd(int begin_chr, int last_pos) {
if (begin_chr > ) return; int cp = fo[begin_chr];
if (last_pos > cp) cp = last_pos; while (cp < inlen) {
if (input[cp] == welcome[begin_chr]) {
if(begin_chr == ) {
tc++;
if (tc == ) tc = ;
} radd(begin_chr + , cp);
} cp++;
} return;
} int solve()
{ int wlen = ;
inlen = (int)input.length(); tc = ; for (int wi = ; wi < wlen; wi++) {
char chr = welcome[wi];
bool found = false;
for (int ii = wi; ii < inlen; ii++) {
if (chr == input[ii]) {
fo[wi] = cp[wi] = ii;
found = true;
break;
}
}
if (!found)
return ;
} radd(, ); return tc;
} int main()
{
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout); int T;
scanf("%d\n", &T);
if (!T) {
cerr << "Check input!" << endl;
exit();
} for (int t = ; t <= T; t++) {
cerr << "solving: #" << t << " / " << T << endl; getline(cin, input); auto result = solve();
printf("Case #%d: %04d\n", t, result);
} fclose(stdin);
fclose(stdout);
return ;
}

Google Code Jam 2009 Qualification Round Problem C. Welcome to Code Jam的更多相关文章

  1. Google Code Jam 2009 Qualification Round Problem B. Watersheds

    https://code.google.com/codejam/contest/90101/dashboard#s=p1 Problem Geologists sometimes divide an ...

  2. Google Code Jam 2009 Qualification Round Problem A. Alien Language

    https://code.google.com/codejam/contest/90101/dashboard#s=p0 Problem After years of study, scientist ...

  3. Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words

    Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...

  4. Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit

    Google Code Jam Qualification Round Africa 2010 Problem A. Store Credit https://code.google.com/code ...

  5. [C++]Infinite House of Pancakes——Google Code Jam 2015 Qualification Round

    Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...

  6. [C++]Standing Ovation——Google Code Jam 2015 Qualification Round

    Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...

  7. Google APAC----Africa 2010, Qualification Round(Problem C. T9 Spelling)----Perl 解法

    原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p2 问题描述: Problem The Latin alphabe ...

  8. Google APAC----Africa 2010, Qualification Round(Problem B. Reverse Words)----Perl 解法

    原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p1 问题描述: Problem Given a list of s ...

  9. Google APAC----Africa 2010, Qualification Round(Problem A. Store Credit)----Perl 解法

    原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p0 问题描述: Problem You receive a cre ...

随机推荐

  1. tmux简单使用指南

    一, ubuntu安装tmux sudo apt-get install tmux 二, tmux使用 1)打开shell,输入命令tmux,,shell下边会出现绿色状态条 2)然后同时按下ctrl ...

  2. Hibernate与 MyBatis的比较

    希望大家指出不对之处. 第一章     Hibernate与MyBatis Hibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jboss的一部分. Myb ...

  3. 编译安装0bda 8179无线网卡

    CentOS下安装USB无线网卡(Obda:8179) 参考:http://blog.163.com/thinki_cao/blog/static/83944875201311593529913/ c ...

  4. 1.django笔记之django基础

    一.django简介 Django是一个开放源代码的Web应用框架,由Python写成.采用了MVC的软件设计模式,即模型M,视图V和控制器C.它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内 ...

  5. Html标签<a>的target属性

    target属性规定了在何处打开超链接的文档. 如果在一个 <a> 标签内包含一个 target 属性,浏览器将会载入和显示用这个标签的 href 属性命名的.名称与这个目标吻合的框架或者 ...

  6. android 中如何分析内存泄漏

    转载:http://blog.csdn.net/fulinwsuafcie/article/details/8363218 前提条件: 1,电脑安装了java 运行环境 2,手机端开启了 USB 调试 ...

  7. Period(poj 1961)

    题目大意: 给你一个字符串,求这个字符串到第i个字符为止的循环节的次数. 比如aabaabaabaab,长度为12.到第二个a时,a出现2次,输出2.到第二个b时,aab出现了2次,输出2.到第三个b ...

  8. 组合数(codevs 1631)

    1631 组合数  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 组合数C(N, K)表示 ...

  9. hadoop启动后jps没有namenode(转)

    hadoop启动后jps没有namenode 一般都是由于两次或两次以上格式化NameNode造成的,有两种方法可以解决: 1.删除DataNode的所有资料 2.修改每个DataNode的names ...

  10. 在竞赛ACM Java处理输入输出

    一.Java之ACM注意点 1. 类名称必须采用public class Main方式命名 2. 在有些OJ系统上,即便是输出的末尾多了一个“ ”,程序可能会输出错误,所以在我看来好多OJ系统做的是非 ...