1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <locale.h>
#include <math.h>
#include <algorithm>
using namespace std;
template <class T>
bool contains(vector<T> const &v, T const &x) {
return ! (v.empty() &&
find(v.begin(), v.end(), x) == v.end());
}
int main(int argc, char *argv[])
{
char *locale;
locale = setlocale(LC_ALL, "");
if(argc==10) {
string line;
ifstream myfile;
int i,j,k,l,m,n,o,p,q;
vector<string> dictionary;
vector<string> used;
myfile.open("ordlista.txt");
if(myfile.is_open()) {
while ( getline(myfile,line)) {
dictionary.push_back(line);
}
}
myfile.close();
for (i=1;i<=argc;++i) {
string word = argv[i];
if(!(contains(used,word)) && contains(dictionary,word)) {
cout << word;
used.push_back(word);
}
for (j=1;j<=argc;++j) { //start Letter 2
if(i!=j) { // start if 2
word = string(argv[i]) + argv[j];
if(!(contains(used,word)) && contains(dictionary,word)) {
cout << word;
used.push_back(word);
}
for (k=1;k<=argc;++k) { //start letter 3
if(k!=j&&k!=i) { // start if 3
word = argv[i] + string(argv[j]) + argv[k];
if(!(contains(used,word)) && contains(dictionary,word)) {
cout << word;
used.push_back(word);
}
for (l=1;l<=argc;++l) { // start letter 4
if(l!=k&&l!=j&&l!=i) { // start if 4
word = argv[i] + string(argv[j]) + argv[k] + argv[l];
if(!(contains(used,word)) && contains(dictionary,word)) {
cout << word;
used.push_back(word);
}
for (m=1;m<=argc;++m) { // start letter 5
if(m!=l&&m!=k&&m!=j&&m!=i) { // start if 5
word = string(argv[i]) + argv[j] + argv[k] + argv[l] + argv[m];
if(!(contains(used,word)) && contains(dictionary,word)) {
cout << word;
used.push_back(word);
}
for (n=1;n<=argc;++n) { // start letter 6
if(n!=m&&n!=l&&n!=k&&n!=j&&n!=i) { // start if 6
word = string(argv[i]) + argv[j] + argv[k] + argv[l] + argv[m] + argv[n];
if(!(contains(used,word)) && contains(dictionary,word)) {
cout << word;
used.push_back(word);
}
for (o=1;o<=argc;++o) { // start letter 7
if(o!=n&&o!=m&&o!=l&&o!=k&&o!=j&&o!=i) { // start if 7
word = string(argv[i]) + argv[j] + argv[k] + argv[l] + argv[m] + argv[n] + argv[o];
if(!(contains(used,word)) && contains(dictionary,word)) {
cout << word;
used.push_back(word);
}
for (p=1;p<=argc;++p) { // start letter 8
if(p!=o&&p!=n&&p!=m&&p!=l&&p!=k&&p!=j&&p!=i) { // start if 8
word = string(argv[i]) + argv[j] + argv[k] + argv[l] + argv[m] + argv[n] + argv[o] + argv[p];
if(!(contains(used,word)) && contains(dictionary,word)) {
cout << word;
used.push_back(word);
}
for (q=1;q<=argc;++q) { //start letter 9
if(q!=p&&q!=o&&q!=n&&q!=m&&q!=l&&q!=k&&q!=j&&q!=i) { // start if 8
word = string(argv[i]) + argv[j] + argv[k] + argv[l] + argv[m] + argv[n] + argv[o] + argv[p] + argv[q];
if(!(contains(used,word)) && contains(dictionary,word)) {
cout << word;
used.push_back(word);
}
} //end if 9
} //end letter 9
} //end if 8
}//end Letter 8
} // end If 7
} //end letter 7
}//end if 6
} //end letter 6
} //end if 5
} // end Letter 5
} //end if 4
} //end Letter 4
} // end if 3
} //end Letter 3
} //end If 2
} //end Letter 2
} //end Letter 1
} else {
cout << "To many or to few arguments";
}
return 0;
}
|