私はC言語では新しく、実際の単語を明らかにするために文字列の入力を解読するプログラムを作ろうと考えていましたが、うまくいきませんでした。ここでは正常に動作して、それの例である:Cのスクランブルを外す文字列
は、Wordを入力します。
マッチ付き合え:
マッチを投稿:ポットは
マッチ:スポット
マッチ:トップス: マッチを停止マッチを停止
私は「aspell」というプログラムから得た単語リストを使用しています。これにより、私は完全なファイルを作成できましたrds。奇妙なのは、「テスト」や「サッカー」のような言葉を入力すると、入力語に元々は存在しない文字を含む単語が返されるということです。私はここで間違って何をしていますか?以下は、ほとんどの作業を行うunscrambleWord関数です。何らかの理由で
Enter Word:football
Match: blastoff
Match: boastful
Match: flatboat
Match: football
Match: lifeboat
Match: softball
、そこのSさんは、試合文字列であるが、文字の数があるように見える。また、私はここで
int unscrambleWord(int fgLetters) {
// integer used for the counter
int i = 0;
// first make sure that the lengths of the word and of the list word is the same
if(strlen(currentLine) == strlen(input)) {
// loop through each letter in the word given
for(i = 0; i < strlen(input); i++) {
// search the line for the current letter, if we find it increment fgLetters
if(strchr(currentLine, input[i]) != NULL)
fgLetters++;
} // end for
// once we have finished looping through the word; evaluate fgLetters
if(fgLetters == strlen(input)) {
// fgLetters will be equal to the length of the word if each letter appears in the word
printf("\tMatch: %s \n", currentLine);
} // end if - evaluate length of fgLetters
}
// return the fgLetters after we have possibly incremented it
return fgLetters;
}
は、サッカーの一例である「サッカー」の例を掲載します同じ。
私はあなたのアルゴリズムが好きです。 – EricSchaefer
はい、これは良い考えです、私はそれを考えなかった! –