Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. #include<cstring>
  4.  
  5. #include<algorithm>
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. void recurse(int);
  12.  
  13. int map[1001];
  14.  
  15. int x;
  16.  
  17. char permut[1001];
  18.  
  19. char a[1001];
  20.  
  21. int c=0,len;
  22.  
  23. int check[200]={0};
  24.  
  25. int prev=-1;
  26.  
  27. bool compare(char a,char b)
  28.  
  29. {
  30.  
  31.  
  32.  
  33.  
  34.  
  35. if(check[a]>=check[b]) return 0;
  36.  
  37. else return 1;
  38.  
  39.  
  40.  
  41. }
  42.  
  43. int main()
  44.  
  45. {
  46.  
  47.  
  48.  
  49.  
  50.  
  51. int mark=1,i;
  52.  
  53. for(i=65;i<=90;i++)
  54.  
  55. {
  56.  
  57. check[i]=mark;
  58.  
  59. mark+=2;
  60.  
  61. }
  62.  
  63. mark=2;
  64.  
  65. for(i=97;i<=122;i++)
  66.  
  67. {
  68.  
  69. check[i]=mark;
  70.  
  71. mark+=2;
  72.  
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. while(scanf("%s%d",a,&x)==2)
  86.  
  87. {
  88.  
  89. prev=-1;
  90.  
  91. c=0;
  92.  
  93.  
  94.  
  95. len=strlen(a);
  96.  
  97. for(i=0;i<=len+2;i++)
  98.  
  99. map[i]=0;
  100.  
  101. sort(a,a+len,compare);
  102.  
  103. recurse(0);
  104.  
  105.  
  106.  
  107. }
  108.  
  109.  
  110.  
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117. void recurse(int source)
  118.  
  119. {
  120.  
  121. int i;
  122.  
  123. int cmap[200]={0};
  124.  
  125.  
  126.  
  127. if(c==x)
  128.  
  129. {
  130.  
  131.  
  132.  
  133.  
  134.  
  135. for(i=0;i<c;i++)
  136.  
  137. printf("%c",permut[i]);
  138.  
  139. puts("");
  140.  
  141.  
  142.  
  143.  
  144.  
  145. }
  146.  
  147. for(i=prev+1;i<len;i++)
  148.  
  149. {
  150.  
  151. if(map[i]==0 && cmap[a[i]]==0)
  152.  
  153. {
  154.  
  155. cmap[a[i]]=1;
  156.  
  157. prev=i;
  158.  
  159. permut[c++]=a[i];
  160.  
  161. map[i]=1;
  162.  
  163. recurse(i);
  164.  
  165. map[i]=0;
  166.  
  167.  
  168.  
  169. c--;
  170.  
  171. }
  172.  
  173.  
  174.  
  175. }
  176.  
  177.  
  178.  
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement