Google Code Jam 2009 Qualification Round Problem C. Welcome to Code Jam
本题的 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 |
Case #1: 0001 |
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的更多相关文章
- Google Code Jam 2009 Qualification Round Problem B. Watersheds
https://code.google.com/codejam/contest/90101/dashboard#s=p1 Problem Geologists sometimes divide an ...
- 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 ...
- 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 ...
- 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 ...
- [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) ...
- [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) ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- annotation(@Retention@Target)详解
一.注解:深入理解JAVA注解 要深入学习注解,我们就必须能定义自己的注解,并使用注解,在定义自己的注解之前,我们就必须要了解Java为我们提供的元注解和相关定义注解的语法. 1.元注解(meta-a ...
- 18.用两个栈实现队列[2StacksToImplementQueue]
[题目] 某队列的声明如下: C++ Code 123456789101112131415 template<typename T> class CQueue { public: ...
- Cocos2d 学习资料推荐
总算找到了一本介绍cocos2d的好书,注意,不是cocos2d-x!这本书叫 <cocos2d 权威指南> 定价99元,淘宝60多元,详细介绍了cocos2d的各个方面!不过你需要有oc ...
- Android dp px转化公式
// DisplayMetrics metrics = getResources().getDisplayMetrics(); // int statusBarHeight = (int) Math. ...
- c# 获取屏幕DPI
方法一:用ManagementClass来获取.需要引入System.Management.dll; using (ManagementClass mc = new ManagementClass(& ...
- Java for LeetCode 029 Divide Two Integers
Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...
- js将map转换成数组
/** * map转数组. * * @param {Map}map * map对象 * @return 数组 */ Share.map2Ary = function(map) { var list = ...
- 读取STL模型
读取二进制格式的STL模型文件 std::ifstream fin;fin.open(stlFilePath, std::ios::in | std::ios::binary);bool isBina ...
- jsp url传值乱码
<Connector port="8080" maxHttpHeaderSize="8192" minProcessors="10" ...
- 二、JavaScript语言--JS基础--JavaScript进阶篇--数组
1.什么事数组 我们知道变量用来存储数据,一个变量只能存储一个内容.假设你想存储10个人的姓名或者存储20个人的数学成绩,就需要10个或20个变量来存储,如果需要存储更多数据,那就会变的更麻烦.我们用 ...