Google Code Jam在线測试题目--Alien Language
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, L, D 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的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- jenkinsfile or pipline 实现微服务自动发布回滚流程
1 #!/usr/bin/env groovy Jenkinsfile node { //服务名称 def service_name = "**" //包名 def service ...
- Android studio 中R.menu的创建
对于Android开发中的menu没有声明的情况: 首先,将鼠标定位到红色的menu上面, 然后,Alt+enter组合键,建立文件menu, 然后将以下代码复制进去: <item androi ...
- 以简单的例子谈一下C#中的COPY
周五晚上加班的时候做一堆ComboBox直接的联动,然后呢,这些cbo的DataSource都是同一个DataTable,当时写代码的时候求快也就没有太注意DataTable的绑定,然后就出了一些小问 ...
- Angular——内置指令
内置指令 ng-app 指定应用根元素,至少有一个元素指定了此属性. ng-controller 指定控制器 ng-show控制元素是否显示,true显示.false不显示 ng-hide控制元素是否 ...
- C# WinForm窗体应用(第四天)
一.点击登录按钮,将两个窗体进行连接,并进行用户名和密码验证. /// <summary> /// 登录设置 /// </summary> /// <param name ...
- 【sqli-labs】 less58 GET -Challenge -Double Query -5 queries allowed -Variation1 (GET型 挑战 双查询 只允许5次查询 变化1)
单引号闭合成功,但是union select结果不对 http://192.168.136.128/sqli-labs-master/Less-58/?id=0' union select 1,2,3 ...
- Sping装配之——自动装配
Sping从两个角度来实现自动化装配: 组件扫描(component scaning):spring会自动发现应用上下文中所创建的bean; 自动装配(autowiring):spring自动满足be ...
- centos7mini版安装pyenv,ipython和jupyter环境.2090513
第一节: 搭建centos7下pyenv,ipython,jupyter环境 pyenv:是一个python多版本管理器,在这个里面可以安装多个版本共存,然后可以安装需求选择版本. ipython:就 ...
- 【转载】使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化
一.创建一个空的项目作为存放整个项目的路径 1.选择 File——>new——>Project ——>Empty Project 2.WorkspaceforTest为项目存放文件夹 ...
- SGU100
Read integers A and B from input file and write their sum in output file. Input Input file contains ...