Guest User

Untitled

a guest
Jun 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4.  
  5. #define MAX_STR_LEN 8
  6. #define MAX_PER_TABLE_SIZE 76543211 // max number = max map size -1
  7.  
  8.  
  9. void per(const char *);
  10. int power(int, int);
  11.  
  12.  
  13. int main(void)
  14. {
  15. char str[MAX_STR_LEN +1];
  16.  
  17. scanf("%s", str);
  18. per(str);
  19.  
  20. return 0;
  21. }
  22.  
  23. void per(const char *full_str)
  24. {
  25. char set_str[MAX_STR_LEN +1];
  26. int full_str_len;
  27. int full_str_count, set_str_count, set_str_push_count;
  28.  
  29. static char save_str[MAX_STR_LEN +1];
  30. static int save_str_pos = 0;
  31.  
  32. static char index_map[MAX_STR_LEN +1];
  33. int index_map_count;
  34. int index;
  35. static bool per_table[MAX_PER_TABLE_SIZE];
  36.  
  37.  
  38. if ( save_str_pos == 0 )
  39. strcpy(index_map, full_str);
  40.  
  41.  
  42. full_str_len = strlen(full_str);
  43.  
  44. for (full_str_count = 0; full_str_count < full_str_len; full_str_count++)
  45. {
  46. for (set_str_count = 0, set_str_push_count = 0; set_str_count < full_str_len; set_str_count++)
  47. if ( set_str_count != full_str_count )
  48. {
  49. set_str[set_str_push_count] = full_str[set_str_count];
  50. set_str_push_count++;
  51. }
  52. set_str[set_str_push_count] = '\0';
  53.  
  54. save_str[save_str_pos] = full_str[full_str_count];
  55.  
  56. save_str_pos++;
  57. per(set_str);
  58. save_str_pos--;
  59. }
  60.  
  61. if ( !full_str_count )
  62. {
  63. for (index = 0, index_map_count = 0; save_str[index_map_count]; index_map_count++)
  64. index += ((long)strchr(index_map, save_str[index_map_count])-(long)index_map) *
  65. power(10, strlen(save_str) - index_map_count -1);
  66.  
  67. if ( !per_table[index] )
  68. {
  69. puts(save_str);
  70. per_table[index] = true;
  71. }
  72. }
  73. }
  74.  
  75. int power(int a, int b)
  76. {
  77. int res = 1, count;
  78. for (count = 0; count < b; count++)
  79. res *= a;
  80. return res;
  81. }
Add Comment
Please, Sign In to add comment