The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Name Factory
By iliasand on 14th May 2019 05:58:28 PM | Syntax: CPP | Views: 17



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. string new_names[500];
  6. int index_name = 0;
  7.  
  8. void moding_name(string , int level = 0);
  9. void name_sort();
  10. int fact(int);
  11.  
  12.  
  13.  
  14. int main() {
  15.     string input;
  16.     cin >> input;
  17.  
  18.     moding_name(input);
  19.     name_sort();
  20.  
  21.     int modes_cnt = fact(input.size());
  22.     for(int i=0 ; i < modes_cnt ; i++)
  23.         if(new_names[i] != input)
  24.             cout << new_names[i] << " ";
  25.  
  26.     return 0;
  27. }
  28.  
  29. void moding_name(string name , int level){
  30.     char tmp;
  31.     int check_level = name.size()-1;
  32.     if(level == check_level){
  33.         new_names[index_name] = name;
  34.         index_name++;
  35.     }else
  36.         for(int i = level ; i <= check_level ; i++){
  37.             tmp = name[level];
  38.             name[level] = name[i];
  39.             name[i] = tmp;
  40.  
  41.             moding_name(name, level+1);
  42.         }
  43. }
  44.  
  45. void name_sort(){
  46.     int d = fact(new_names[0].size());
  47.     for(int i = 0 ; i < d;i++)
  48.         for(int j = 0; j < d-1;j++)
  49.             if(new_names[j] > new_names[j+1]){
  50.                 string tmp = new_names[j];
  51.                 new_names[j] = new_names[j+1];
  52.                 new_names[j+1] = tmp;
  53.             }
  54. }
  55.  
  56. int fact(int n){
  57.     if(n == 1)
  58.         return  1;
  59.     else
  60.         return n * fact(n-1);
  61. }



  • Recent Pastes