Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <algorithm>
- #include <math.h>
- using namespace std;
- void perest(long p[10]);
- long p[10];
- char b[10];
- long m;
- int main()
- {
- freopen("input.txt","r", stdin);
- freopen("output.txt", "w",stdout);
- int n,j;
- cin>>n>>m;
- for (int i=1; i<=n; i++)
- b[i] = 'A' + i - 1;
- for (int i = 0; i<=m; i++)
- p[i] = i;
- do
- {
- perest(p);
- j = m;
- while (j>0 && p[j] == j+n-m){
- cout<<p[j];
- j--;
- }
- cout<<endl;
- if (j>0)
- {
- p[j]++;
- for (int i=j+1; i<=m; i++)
- p[i] = p[i-1] + 1;
- }
- }
- while (j>0);
- return 0;
- }
- void perest(long p[10])
- {
- long x,l,r,j,k;
- while (p[0] == 0)
- {
- for (int i=1; i<=m; i++)
- cout<<b[p[i]];
- cout<<endl;
- j = m;
- while (p[j]<p[j-1])
- j--;
- k = m;
- while (p[k]<p[j-1])
- k--;
- x = p[k];
- p[k] = p[j-1];
- p[j-1] = x;
- l = j;
- r = m;
- while (l < r)
- {
- x = p[l];
- p[l] = p[r];
- p[r] = x;
- l++;
- r--;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement