Jump to content

Permutations.cpp

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
LogicKills

LogicKills

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts
Whoops

Edited by LogicKills, 21 October 2008 - 12:11 AM.
I uploaded wrong version :p

http://logickills.org
Science - Math - Hacking - Tech

#2
LogicKills

LogicKills

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts
The version I meant to paste :]

/*

  Coded by: LogicKills;

       For: logickills.org;

    Reason: Somene asked for help;

    

    Notes: All it does it write to permutations.txt

           Doesn't check for existance, or error.

           Overwrites permutations from older execution.

           Made this in about 5 min :]

           

*/


#include <iostream>

#include <algorithm>

#include <string>

#include <fstream>


using std::string;   using std::cout;

using std::endl;     using std::cin;

using std::ofstream;



int main(int argc, char *argv[])

{

    

	if (argc != 2)

       {     

             cout << "\nUsage: prm [ word ]  " << endl;

             cout << "  \nNote: " << endl;

             cout << " permutations.txt will be saved in the same dir that the prm.exe is in." << endl;

            

             return 1;

       }


      

    string x = argv[1];

    int z = 1;

    


    

    ofstream outFile;

    outFile.open("permutations.txt");

    outFile << "Permutations of the word " << x << endl;

    sort(x.begin(),x.end());

    outFile << x << std::endl;

    while(next_permutation(x.begin(), x.end()))

    {

           outFile << x << endl;

           z++;

    }

    outFile << "Total number of permutations: " << z << endl;

         


  return 0;

}



http://logickills.org
Science - Math - Hacking - Tech