저는 학교 프로젝트를 진행하고 있으며, 제가 생각하기에 작은 부분 일뿐입니다. 알아낼 수 없습니다. C++의 Anagram 솔버
#include <iostream>
#include <fstream>
#include <string>
#include <locale>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int main(int argc, char* argv[])
{
set<string> setwords;
ifstream infile;
infile.open("words.txt"); //reads file "words.txt"
string word = argv[1]; // input from command line
transform(word.begin(), word.end(), word.begin(), tolower); // transforms word to lower case.
sort(word.begin(), word.end()); // sorts the word
vector<string> str; // vector to hold all variations of the word
do {
str.push_back(word);
}
while (next_permutation(word.begin(), word.end())); // pushes all permutations of "word" to vector str
if (!infile.eof())
{
string items;
infile >> items;
setwords.insert(items); //stores set of words from file
}
system("PAUSE");
return 0;
}
가 지금은 벡터
str
에 저장된 파일에서 단어와 순열을 비교하고 실제 단어 사람을 인쇄 할 필요가 : 여기
는 내가 지금까지 가지고있는 것입니다.
나는 set 클래스의 find 메소드를 사용해야한다는 것을 알고있다. 나는 그걸 어떻게 가는지 확신 할 수 없다. 나는 행운을 빌어 이와 같은 것을 시도했지만, 내 사고 과정은 아마 틀렸다.
for (unsigned int i = 0; i < str.size(); i++)
if (setwords.find(word) == str[i])
cout << str[i] << endl;
여러분이 올바른 방향으로 나를 도울 수 있다면 큰 감사 할 것입니다.
+1 당신을 위해 코드를 작성하는 대신 우리가 노력하고 게시하는 장소에 게시 할 수 있습니다. 드문 경우입니다. –