I ran the above which implements up to 4 character words. It took about 94 seconds. Im not sure its the best way to do what i want but it makes sense to me. Any comments on making it faster? My algorithm seems to hit every combo i think. The DOS window doesnt hold all the lines so i cant search back to the begining only like 200 lines or something.Code:/* Words By: Gerald Eckert Prints all possible combinations of the alphabet up 5 charcters in length. */ #include <iostream> using namespace std; //The alphabet const char alphabet[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; int main() { //Iterate up to 5 character words. for(int i=0;i<5;i++) { switch(i) { //For 1 character words. case 0: for(int a=0;a<25;a++) cout<<alphabet[a]<<endl; break; //For 2 character words. case 1: for(int a=0; a<26 ;a++) for(int b=0;b<26;b++) cout<<alphabet[a]<<alphabet[b]<<endl; break; //For 3 character words. case 2: for(int a=0;a<26;a++) for(int b=0;b<26;b++) for(int c=0;c<26;c++) cout<<alphabet[a]<<alphabet[b]<<alphabet[c]<<endl; break; //For 4 character words. case 3: for(int a=0;a<26;a++) for(int b=0;b<26;b++) for(int c=0;c<26;c++) for(int d=0;d<26;d++) cout<<alphabet[a]<<alphabet[b]<<alphabet[c]<<alphabet[d]<<endl; //For 5 character words case 4:break; } } return(0); }




Reply With Quote
