Problem

After years of study, scientists at Google Labs have discovered an alien language transmitted from a faraway planet. The alien language is very unique in that every word consists of exactly L lowercase
letters. Also, there are exactly D words in this language.

Once the dictionary of all the words in the alien language was built, the next breakthrough was to discover that the aliens have been transmitting messages to Earth for the past decade. Unfortunately,
these signals are weakened due to the distance between our two planets and some of the words may be misinterpreted. In order to help them decipher these messages, the scientists have asked you to devise an algorithm that will determine the number of possible
interpretations for a given pattern.

A pattern consists of exactly L tokens. Each token is either a single lowercase letter (the scientists are very sure that this is the letter) or a group of unique lowercase letters surrounded
by parenthesis ( and ). For example: (ab)d(dc) means the first letter is either a or b, the second letter is definitely d and the last letter is either d or c. Therefore, the pattern (ab)d(dc) can stand for either one of these 4 possibilities: add, adc, bdd,
bdc.

Input

The first line of input contains 3 integers, LD and N separated by a space. D lines follow, each containing one word of length L.
These are the words that are known to exist in the alien language. N test cases then follow, each on its own line and each consisting of a pattern as described above. You may assume that all known words provided are unique.

Output

For each test case, output

Case #X: K

where X is the test case number, starting from 1, and K indicates
how many words in the alien language match the pattern.

Limits

Small dataset

1 ≤ L ≤ 10

1 ≤ D ≤ 25

1 ≤ N ≤ 10

Large dataset

1 ≤ L ≤ 15

1 ≤ D ≤ 5000

1 ≤ N ≤ 500

思路L:对于每个pattern,字典中每个词与它匹配。

代码:

/*2014-10-16
*zhuangweibiao
*/
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
bool match(string target, string pattern)
{
int index = 0;
for(int i = 0; i < pattern.length(); ++i)
{
if(pattern[i] == '(')
{
bool found = false;
while(pattern[++i] != ')')
{
if(pattern[i] == target[index])
found = true;
}
if(!found)
return false;
index++;
}
else
{
if(pattern[i] != target[index])
return false;
index++;
}
}
return true;
}
int main()
{
ifstream ifile("A-large-practice.in");
ofstream ofile("match2.txt");
int L, D, N;
string str[5001];
ifile >> L >> D >> N;
for(int i = 0; i < D; ++i)
ifile >> str[i];
string pattern;
for(int i = 0; i < N; ++i)
{
ifile >> pattern;
int count = 0;
for(int j = 0; j < D; ++j)
{
if(match(str[j], pattern))
count++;
}
ofile << "Case #" << i + 1 << ": " << count << endl;
}
return 0;
}

Google Code Jam在线測试题目--Alien Language的更多相关文章

  1. [Google Code Jam (Qualification Round 2014) ] B. Cookie Clicker Alpha

    Problem B. Cookie Clicker Alpha   Introduction Cookie Clicker is a Javascript game by Orteil, where ...

  2. [Google Code Jam (Qualification Round 2014) ] A. Magic Trick

    Problem A. Magic Trick Small input6 points You have solved this input set.   Note: To advance to the ...

  3. [C++]Store Credit——Google Code Jam Qualification Round Africa 2010

    Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...

  4. [C++]Saving the Universe——Google Code Jam Qualification Round 2008

    Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...

  5. 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 ...

  6. 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 ...

  7. Google Code Jam 2010 Round 1C Problem A. Rope Intranet

    Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...

  8. jsfiddle在线測试Html、CSS、JavaScript——http://jsfiddle.net/

    jsfiddle在线測试Html.CSS.JavaScript,并展示測试结果 1.选择jQuery1.9.1 2.选择jQuery UI 1.9.2 3.Html <ul id="n ...

  9. Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha

    Introduction Cookie Clicker is a Javascript game by Orteil, where players click on a picture of a gi ...

随机推荐

  1. SQLSERVER SQL性能优化技巧

    这篇文章主要介绍了SQLSERVER SQL性能优化技巧,需要的朋友可以参考下 1.选择最有效率的表名顺序(只在基于规则的优化器中有效)       SQLSERVER的解析器按照从右到左的顺序处理F ...

  2. jQuery——尺寸位置

    获取宽:$(".box").width() 设置宽:$(".box").width(200) 获取高:$(".box").height() ...

  3. C# 字符串的入门

    1."@"表示字符串中的"\"不当成转义符. 2.转义符或者特殊处理的一些字符只是针对于代码中直接写出的字符串中,对于程序运行中读取出来的转义符或者特殊处理的字 ...

  4. [nodejs]在mac环境下如何将node更新至最新?

    在mac下安装angular-cli时,报出较多错误.初步怀疑是因为node环境版本过低导致. 在mac下,需要执行如下几步将node更新至最新版本,也可以更新到指定版本 1. sudo npm ca ...

  5. HUD 1426 Sudoku Killer (DFS)

    链接 : Here! 思路 : 记录下所有 "?" , 出现的位置, 然后 $DFS$ 一下, 对于每个位置来说都可以填充 $9$ 种数值, 然后对于判断填充是否合法需要三个标记数 ...

  6. linux安装openjdk

    使用yum查找jdk: yum search java | grep jdk 执行安装命令:yum install java-1.8.0-openjdk

  7. 弹层蒙版(mask),ios滚动穿透,我们项目的解决方案

    问题描述 项目开发遇到一个ios独有的问题,在wkwebview中稳定复现 问题: 弹出一个蒙版,当在蒙版上面滑动的时候蒙版后面的内容滚动了 这当然是ios的bug,但是经过我们测试iphone7也会 ...

  8. Mysql数据库操作(二)

    存储过程 1.创建过程 delimiter // create procedure p1() BEGIN select * from t1; END// delimiter; --执行存储过程 cal ...

  9. PAT 1115 Counting Nodes in a BST

    A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...

  10. node.js 中的package.json文件怎么创建?

    最近在用webstorm和nodejs做一些东西,老是各种混乱,今天上午创建一个新的项目,结果发现,npm init之后,并没有出现package.json,并没有太明确他的功能的小姑娘表示十分的惊慌 ...