Given ambyngrid
of letters, (),
and a list of words, find the location in the grid at which the word can be found. A word matches a straight, uninterrupted line of letters in the grid. A word can match the letters in the grid regardless of case (i.e. upper and lower case letters are to be
treated as the same). The matching can be done in any of the eight directions either horizontally, vertically or diagonally through the grid.
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and
there is also a blank line between two consecutive inputs.
The input begins with a pair of integers,mfollowed byn,in
decimal notation on a single line. The nextmlines containnletters each; this is the grid of letters in which the words of the list must be found. The letters in the grid may be in upper or lower case. Following the grid of letters, another
integerkappears on a line by itself (). The nextklines of
input contain the list of words to search for, one word per line. These words may contain upper and lower case letters only (no spaces, hyphens or other non-alphabetic characters).
For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.
For each word in the word list, a pair of integers representing the location of the corresponding word in the grid must be output. The integers must be separated by a single space. The first integer is the line in the grid where the first letter of the given
word can be found (1 represents the topmost line in the grid, andmrepresents the bottommost line). The second integer is the column in the grid where the first letter of the given word can be found (1 represents the leftmost column in the grid,
andnrepresents the rightmost column in the grid). If a word can be found more than once in the grid, then the location which is output should correspond to the uppermost occurence of the word (i.e. the occurence which places the first letter of
the word closest to the top of the grid). If two or more words are uppermost, the output should correspond to the leftmost of these occurences. All words can be found at least once in the grid.
1
8 11
abcDEFGhigg
hEbkWalDork
FtyAwaldORm
FtsimrLqsrc
byoArBeDeyv
Klcbqwikomk
strEBGadhrb
yUiqlxcnBjf
4
Waldorf
Bambi
Betty
Dagbert
2 5
2 3
1 2
7 8
Miguel Revilla
2000-08-22
【大意】:
输入:
给你一个由字母组成的网格,M行N列。寻找一个单词在网格中的位置。一个单词匹配网格中联系不间断的字母。可以沿任意方向匹配,一共可以匹配八个方向。忽略大小写。
需要匹配的字符串有K个。
输出:
每组输出之间都一行空行。
m n:m代表匹配的最上面的行
n代表匹配的最下面的行
如果结果有多个,只输出匹配串。要求:匹配串的第一个字母必须是最高最左的。结果至少有一个。
【代码】:
-
-
-
-
-
-
-
-
-
-
#include<stdio.h>
-
#include<string.h>
-
-
charMatrix[51][51];
-
charstr[21],temp[21];
-
intStartR,StartC;
-
-
intMatch(intM,intN,int&StartR,int&StartC){
-
inti,j,k,flag;
-
StartR=51,StartC=51;
-
intlen=strlen(str);
-
for(i=0;i<M;i++){
-
for(j=0;j<N;j++){
-
flag=1;
-
-
if(j+len<=N){
-
flag=0;
-
for(k=0;k<len;k++){
-
if(str[k]!=Matrix[i][j+k]){
-
flag=1;
-
break;
-
}
-
}
-
if(flag==0){
-
if(StartR>i+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
elseif(StartR==i+1&&StartC>j+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
}
-
}
-
-
if(j-len+1>=0){
-
flag=0;
-
for(k=0;k<len;k++){
-
if(str[k]!=Matrix[i][j-k]){
-
flag=1;
-
break;
-
}
-
}
-
if(flag==0){
-
if(StartR>i+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
elseif(StartR==i+1&&StartC>j+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
}
-
}
-
-
if(i+len<=M){
-
flag=0;
-
for(k=0;k<len;k++){
-
if(str[k]!=Matrix[i+k][j]){
-
flag=1;
-
break;
-
}
-
}
-
if(flag==0){
-
if(StartR>i+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
elseif(StartR==i+1&&StartC>j+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
}
-
}
-
-
if(i-len+1>=0){
-
flag=0;
-
for(k=0;k<len;k++){
-
if(str[k]!=Matrix[i-k][j]){
-
flag=1;
-
break;
-
}
-
}
-
if(flag==0){
-
if(StartR>i+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
elseif(StartR==i+1&&StartC>j+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
}
-
}
-
-
if(j+len<=N&&i-len+1>=0){
-
flag=0;
-
for(k=0;k<len;k++){
-
if(str[k]!=Matrix[i-k][j+k]){
-
flag=1;
-
break;
-
}
-
}
-
if(flag==0){
-
if(StartR>i+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
elseif(StartR==i+1&&StartC>j+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
}
-
}
-
-
if(j+len<=N&&i+len<=M){
-
flag=0;
-
for(k=0;k<len;k++){
-
if(str[k]!=Matrix[i+k][j+k]){
-
flag=1;
-
break;
-
}
-
}
-
if(flag==0){
-
if(StartR>i+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
elseif(StartR==i+1&&StartC>j+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
}
-
}
-
-
if(j-len+1>=0&&i-len+1>=0){
-
flag=0;
-
for(k=0;k<len;k++){
-
if(str[k]!=Matrix[i-k][j-k]){
-
flag=1;
-
break;
-
}
-
}
-
if(flag==0){
-
if(StartR>i+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
elseif(StartR==i+1&&StartC>j+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
}
-
}
-
-
if(j-len+1>=0&&i+len<=M){
-
flag=0;
-
for(k=0;k<len;k++){
-
if(str[k]!=Matrix[i-k][j+k]){
-
flag=1;
-
break;
-
}
-
}
-
if(flag==0){
-
if(StartR>i+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
elseif(StartR==i+1&&StartC>j+1){
-
StartR=i+1;
-
StartC=j+1;
-
}
-
}
-
}
-
}
-
}
-
return0;
-
}
-
-
intmain(){
-
inti,j,Case,k,M,N;
-
-
while(scanf("%d",&Case)!=EOF){
-
while(Case--){
-
scanf("%d%d",&M,&N);
-
-
for(i=0;i<M;i++){
-
scanf("%s",temp);
-
for(j=0;j<N;j++){
-
Matrix[i][j]=temp[j];
-
-
if(Matrix[i][j]>='A'&&Matrix[i][j]<='Z'){
-
Matrix[i][j]=Matrix[i][j]-'A'+'a';
-
}
-
}
-
}
-
scanf("%d",&k);
-
-
for(i=0;i<k;i++){
-
scanf("%s",str);
-
intlen=strlen(str);
-
-
for(j=0;j<len;j++){
-
if(str[j]>='A'&&str[j]<='Z'){
-
str[j]=str[j]-'A'+'a';
-
}
-
}
-
-
Match(M,N,StartR,StartC);
-
printf("%d%d\n",StartR,StartC);
-
}
-
-
if(Case){
-
printf("\n");
-
}
-
}
-
}
-
return0;
-
}
-
-
-
分享到:
相关推荐
此扩展将在每个新网页上隐藏waldorf。 当你找到他时,点击他! waldorf正在旅途中。 他的目标是访问世界上的每一个网页。 如果您碰巧找到他,请点击他,他将在您正在查看的页面上徘徊在另一个位置。 Waldorf在哪里...
Waldorf在哪里是一个简单的扩展,它将Waldorf添加到您访问的每个页面。 他将被随机放置在页面上。 如果找到他,只需单击他。 您会收到一个弹出窗口,告诉您找到他所需的时间。 如果Waldorf令人讨厌,则可以使用工具...
自述文件此自述文件通常会记录启动和运行应用程序所需的任何步骤。这个存储库是做什么用的? 快速总结版本我该如何设置? 设置摘要配置依赖关系数据库配置如何运行测试部署说明贡献指南编写测试代码审查其他指南我和...
Waldorf是用Python编写的高效并行任务执行框架。 它是为在中国北京研究算法而开发的。 Waldorf基于,并以芹菜为原料,从得名。 它可以通过在多台计算机上分布以Python函数编写的并发子任务并自动输出集合来加快诸如...
Nelson Waldorf学校Amazon.ca筹款活动。 此扩展将学校的Amazon Associates附属标签应用于购买商品,当他们访问Amazon.ca时,学校就可以收到用于筹款的收益。 支持语言:English
// it's much better to use Blofeld's MIDIIn port for SuperColler's MIDIOut, instead of USB // also connect the USB cable to receive sysex messages coming from Blofeld ~blofeld = Blofeld .new.connect( ...
mw1utils:用于Waldorf微波的工具。 包含的工具:mw1cardlist,mw1wav,mw1userwaves,USERWAV4。 Klaus Michael Indlekofer版权所有(c)1993-2017。 版权所有。 注意:有特殊限制。 请参阅下面和发行版中的免责...
文字冒险Computer AG在Offenburg的Waldorf学校进行的文字冒险
s上针对MFCC数据训练src/audio_waldorf_statler.ipynb src/create_visual_feature_csv.py ...创建视觉功能csv文件src/utils.py ...每个项目需要的著名utils.py文件src/visual_feat_ext.py ...辅助功能用于视觉特征...
会议将于1963年4月16~18日在纽约的沃多尔夫-阿斯托里亚星光顶楼(Waldorf Astoria Starlight-Roof)举行。其中有七篇论文是关于量子电子学及有关题目的, 八篇是关于光激射器结构的, 七篇是关于工作物质——光谱学的, ...
有关b-ber背后原理的更多信息,请阅读Triple Canopy的创意总监Caleb Waldorf撰写的“ ”。 要查看使用b-ber制作的示例项目,请访问我们的或在Triple Canopy 。 虽然还有其他用于将内容导出为不同格式的框架,但是b...
Waldorf Rack Attack 远程 GUI 的 Java 实现。
这是由我(Andre Popovitch)和我的朋友Zeph Balsley和Joseph Waldorf在Cocos2d-x中制作的游戏。
当前,诸如ENEM和ENCCEJA之类的教学验证是基于国家公共课程基础(BNCC)的内容。 尽管如此,也许有人希望选择其他教育手段,例如古典教育,华尔道夫,慢学或蒙台梭利。 为此,该资料库还将提供包含BNCC每学年预期的...