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. Struts之 拦截器配置 ( Interceptor )

    struts2体系结构的核心就是拦截器. 以链式执行,对真正要执行的方法(execute())进行拦截.首先执行Action配置的拦截器,在Action和Result执行之后,拦截器再一次执行(与先前 ...

  2. sql 列集合转换成逗号分隔的字符类型

    CREATE function [dbo].[getGroupPath](@groupId int) returns nvarchar(2000) as begin declare @path nva ...

  3. Java&Xml教程(七)使用JDOM修改XML文件内容

    JDOM提供了非常灵活的方式操作XML文件,使用JDOM非常简单而且代码简洁可读性强.前面我们学习了如何使用JDOM解析XML文件,本节介绍如何使用JDOM修改XML文件内容. 在这个教程中,我们准备 ...

  4. Java&Xml教程(三)使用DOM方式修改XML文件内容

    DOM解析方式也可用于修改XML数据,我们可以使用它完成新增元素.删除元素.修改元素值.修改元素属性等操作. 我们的XML文件,内容如下: employee.xml <?xml version= ...

  5. CSS——img标签消除3px

    1.dispaly:block 2.float:left 这两种都可以消除3px

  6. css页面布局总结

    W3C标准:是万维网制定的一系列标准,包括结构化标准语言(html.xml),表现 标准语言(css),行为标准语言(DOM,ECMAScript<javascript>)组成.这个标准倡 ...

  7. Java类及成员

    Java类及成员 类 类是对一类事物的的描述,是抽象的概念上的定义:类是创建对象的模板: public class TestClass { public static void main(String ...

  8. python numpy array 与matrix 乘方

    python numpy array 与matrix 乘方 编程语言 waitig 1年前 (2017-04-18) 1272℃ 百度已收录 0评论 数组array 的乘方(**为乘方运算符)是每个元 ...

  9. java 导入导出的 命令

    $exp lddba/ld_321@192.168.1.3/testora file=E:\db_bak\ld20170219_1testora.dmp log=E:\db_bak\ld2017021 ...

  10. 使用Flask+uWsgi的方式部署一个blog网站

    本文参考以下文章:https://www.yukunweb.com/2017/12/ubuntu-nginx-uwsgi-flask-app/ 需要学习的地方 nginx+uwsgi部署flask应用 ...