Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <cstdio>
- #include <map>
- using namespace std;
- /* Note: words.txt is the original wordlist, words2.txt is the list of scrambled words, and words4.txt is the unscrambled version of words2.txt. */
- int alpha(char X) //This isn't bugged
- {
- (int)X;
- return X;
- }
- int main()
- {
- ofstream newFile;
- newFile.open("C:\\Users\\Owner\\My Documents\\Words4.txt");
- int z;
- map <string, string> compare;
- ifstream myFile("C:\\Users\\Owner\\My Documents\\Words.txt");
- if(!myFile){
- cout << "Cannot open file.";
- cin>>z;
- exit (1);
- }
- char str[30]={};
- char strInit[30]={};
- char temp;
- int check=0;
- while(myFile){
- myFile.getline(str, 30);
- int h=0;
- for (; str[h] != 0; h++)//setting the initial version of str
- {
- strInit[h]=str[h];
- }
- strInit[h+1]='\0'; //I didn't know if the for loop would include the null char
- cout<<strInit;
- for (int i=0; str[i] != 0; i++) //alphabetizes the current string (apple would become aelpp)
- {
- for (int j=i; j>0; j--)
- {
- if (alpha(str[j-1])>alpha(str[j])) //check is for int checking
- {
- temp=str[j-1]; //temp is for character swapping
- str[j-1]=str[j];
- str[j]=temp;
- }
- else
- {
- check=alpha(str[j]);
- }
- }
- }
- compare[str]=strInit;
- }
- myFile.close();
- ifstream cinFile("C:\\Users\\Owner\\My Documents\\Words2.txt");
- if(!cinFile){
- cout << "Cannot open file.";
- cin>>z;
- exit (1);
- }
- char cinstr[30];
- char cinstrInit[30];
- char cintemp;
- int cincheck=0;
- while(cinFile){
- cinFile.getline(cinstr, 30);
- int H=0;
- for (; cinstr[H] != 0; H++)//setting the initial version of str
- {
- strInit[H]=str[H];
- }
- strInit[H+1]='\0'; //I didn't know if the for loop would include the null char
- for (int I=0; cinstr[I] != 0; I++) //alphabetizes the current string (apple would become aelpp)
- {
- for (int J=I; J>0; J--)
- {
- if (alpha(cinstr[J-1])>alpha(cinstr[J])) //check is for int checking
- {
- cintemp=cinstr[J-1]; //temp is for character swapping
- cinstr[J-1]=cinstr[J];
- cinstr[J]=cintemp;
- }
- else
- {
- cincheck=alpha(cinstr[J]);
- }
- }
- }
- cout<<compare[cinstr]<<"\n";
- newFile<<compare[cinstr]<<",";
- }
- cin>>z;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement