【发布时间】:2016-12-05 20:33:03
【问题描述】:
我正在尝试创建一个单词搜索益智游戏,要求用户输入他们认为在数组中的单词,如果找到该单词,则给用户一分(总共 10 分,之后会打印一条祝贺信息)。
在这段代码中,我有一个常规数组,但根据一些研究,我认为二维数组可能更好。你觉得呢?你有没有什么想法?具体来说,我对应该考虑哪种搜索算法感兴趣
#include <iostream>
using namespace std;
int main() {
// your code goes here
cout<<"=================================================================================="<<endl;
cout<<"|| ||"<<endl;
cout<<"|| Welcome to the ECE 114 Game Design! ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"=================================================================================="<<endl;
cout<<"This is a sample output"<<endl;
//We want to ask the user to enter a word that they think the cross-word puzzle contains
//if the puzzle contains that word, we tell the user they are correct and update their points
//score by 1. Total of 10 points to gain, when the points score reaches 10 the user gets congratulatory message
string myArray[] = { "A B C D E F G H
S P A D E T R Y
T I G O A L E A
T R A I N E A W
O A P B E A T N "};
//The first array above will just be a visual for the player to see
//This second array is the one that I will use to search for words
char wordBank[5][8] = [[ 'A', 'B ','C', 'D', 'E', 'F', 'G', 'H'],
['S','P', 'A', 'D', 'E', 'T', 'R', 'Y'],
['T', 'I', 'G', 'O', 'A', 'L', 'L', 'E', 'A'],
['T', 'R','A', 'I', 'N', 'E', 'A', 'W'],
['O', 'A', 'P', 'B', 'E', 'A', 'T', 'N']];
cout<<myArray<<endl;
return 0;
}
【问题讨论】:
-
这是一个字符数组(或二维)数组比一个只包含一个字符串的字符串数组更好的地方。
-
这段代码可以编译吗?我怀疑在数组声明中的字母
H之后会有警告或错误。 -
@ThomasMatthews 我将在一秒钟内使用二维数组对其进行更新。并且代码没有编译。我现在只是在写伪代码;我的算法不太正确
-
查看
std::string::find以搜索字符串(水平方向)。