Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #include <string.h>
- #define MAX_STR_LEN 8
- #define MAX_PER_TABLE_SIZE 76543211 // max number = max map size -1
- void per(const char *);
- int power(int, int);
- int main(void)
- {
- char str[MAX_STR_LEN +1];
- scanf("%s", str);
- per(str);
- return 0;
- }
- void per(const char *full_str)
- {
- char set_str[MAX_STR_LEN +1];
- int full_str_len;
- int full_str_count, set_str_count, set_str_push_count;
- static char save_str[MAX_STR_LEN +1];
- static int save_str_pos = 0;
- static char index_map[MAX_STR_LEN +1];
- int index_map_count;
- int index;
- static bool per_table[MAX_PER_TABLE_SIZE];
- if ( save_str_pos == 0 )
- strcpy(index_map, full_str);
- full_str_len = strlen(full_str);
- for (full_str_count = 0; full_str_count < full_str_len; full_str_count++)
- {
- for (set_str_count = 0, set_str_push_count = 0; set_str_count < full_str_len; set_str_count++)
- if ( set_str_count != full_str_count )
- {
- set_str[set_str_push_count] = full_str[set_str_count];
- set_str_push_count++;
- }
- set_str[set_str_push_count] = '\0';
- save_str[save_str_pos] = full_str[full_str_count];
- save_str_pos++;
- per(set_str);
- save_str_pos--;
- }
- if ( !full_str_count )
- {
- for (index = 0, index_map_count = 0; save_str[index_map_count]; index_map_count++)
- index += ((long)strchr(index_map, save_str[index_map_count])-(long)index_map) *
- power(10, strlen(save_str) - index_map_count -1);
- if ( !per_table[index] )
- {
- puts(save_str);
- per_table[index] = true;
- }
- }
- }
- int power(int a, int b)
- {
- int res = 1, count;
- for (count = 0; count < b; count++)
- res *= a;
- return res;
- }
Add Comment
Please, Sign In to add comment