Advertisement
UMME_RUKAYA13

Untitled

Nov 22nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,n,k,i,j,l,ans;
  6.  
  7. scanf("%d",&t);
  8. for(i=1; i<=t; i++)
  9. {
  10. scanf("%d %d",&n,&k);
  11. char s[n];
  12. for(j=0; j<n; j++)
  13. {
  14. s[j]='A'+j;
  15. }
  16. s[n]=0;
  17. ans=1;
  18. for(j=1; j<=n; j++)
  19. {
  20. ans=ans*j;
  21. }
  22. printf("Case %d:\n",i);
  23. if(ans<k)
  24. {
  25.  
  26. for(l=0; l<ans; l++)
  27. {
  28. printf("%s\n",s);
  29. next_permutation(s,s+n);
  30.  
  31. }
  32. }
  33. else
  34. {
  35. for(l=0; l<k; l++)
  36. {
  37. printf("%s\n",s);
  38. next_permutation(s,s+n);
  39.  
  40. }
  41. }
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement