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 ...
随机推荐
- Js控制样式的诸多方法
function TableCss(options){ //如果没参数,就退出 if(arguments.length < 1 || !document.getElementById(optio ...
- Task.Run 和 Task.Factory.StartNew
在.Net 4中,Task.Factory.StartNew是启动一个新Task的首选方法.它有很多重载方法,使它在具体使用当中可以非常灵活,通过设置可选参数,可以传递任意状态,取消任务继续执行,甚至 ...
- ansible publishing service
# ansible 初始化服务机 - hosts: newserver vars: - basedir: opt tasks: - name: 安装常用依赖环境 yum: name={{ item } ...
- Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'empid' in 'class cn.happy.entity.Emp'
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.i ...
- 解决:efi usb device has been blocked by the current security policy
解决:efi usb device has been blocked by the current security policy 问题描述:U盘装系统或者其他操作时,是因为BIOS安全策略,出现上述 ...
- PHP开发之旅-表单验证
一.创建表单 <form name = "login" method = "post" action="contact.php?action=l ...
- Raspberry Pi开发之旅-光照强度检测(BH1750)
一.前期准备 1.环境要求 GY30模块(BH1750FVI传感器),树莓派系统,python-smbus,iic开启 2.取消对IIC驱动的黑名单 nano /etc/modprobe.d/rasp ...
- html5——表单
type类型 email //输入email格式 tel //手机号码 url //只能输入url格式 number //只能输入数字 search //搜索框 range //范围 滑动条 colo ...
- HTML5易漏知识点锦集
本文通过对w3schoolHTML5基础教程,整理出比较常见的却又容易遗忘或者忽略的HTML5相关知识点.本文的标题顺序与w3school中的HTML5基础教程标题顺序保持一致.适合翻阅和复习. 1. ...
- POJ——3169Layout(差分约束)
POJ——3169Layout Layout Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14702 Accepted ...