我試圖創建一個詞搜索益智遊戲,要求用戶輸入他們認爲是在數組中的單詞,如果找到該單詞,則給用戶一分(總共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;
}
這是一個數組(或二維)字符數組比一個只包含一個字符串的字符串數組更好的地方。 –
也許注意一下[如何向家庭作業問題尋求幫助](http://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions)。 – wally
此代碼是否正在編譯?我懷疑數組聲明中的字母「H」後會出現警告或錯誤。 –