-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLight Oj 1023 - Discovering Permutations
175 lines (153 loc) · 3.64 KB
/
Light Oj 1023 - Discovering Permutations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
/*Header file ends here*/
#define f(i,j,n) for(int i=j; i<n; i++)
#define fu(i,j,n) for(int i=j; i>n; i--)
#define c(x, t) x t;cin>>t;
#define ft int t;scanf("%d", &t);for(int c=1; c<=t; c++)
#define w(n) while(n--)
#define unvisited -1
#define visited 1
#define debug printf("\n<<CameHere<<\n")
#define mem(x,y) memset(x,y,sizeof(x))
#define pal(temp) pali(temp, 0, temp.size()-1)
#define nl cout<<endl
#define eps 1e-9
#define inf 1<<30
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fin(prob) freopen("prob.in", "r", stdin)
#define fout(prob) freopen("prob.out", "w+", stdout)
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define pi (double)3.141592653589793
#define deb(x) cerr << #x << " = " << x << endl;
/*Macro ends here*/
using namespace std;
typedef string st;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ii> vii;
typedef deque<int> di;
/*typedef ends here*/
template <class T>T abs(T a, T b=0)
{
if(b==0)
{
if(a<0) return -a;
return a;
}
if(a>b) return a-b;
return b-a;
}
template<class T>inline T gcd(T a, T b)
{
if(a<0)return gcd(-a,b);
if(b<0)return gcd(a,-b);
return (b==0)?a:gcd(b,a%b);
}
template<class T, class U>inline T power(T a, U b)
{
if(b==0) return 1;
if(b==1) return a;
T temp=pow(a, b/2);
return temp*temp*pow(a, b%2);
}
bool pali(string temp, int i, int j)
{
if(i>=j) return true;
if(temp[i]==temp[j]) return pali(temp, i+1, j-1);
return false;
}
/*Functions for power, gcd, abs and palindrome ends here*/
/// ********* debug template bt Bidhan Roy *********
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p )
{
return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v )
{
os << "{";
typename vector< T > :: const_iterator it;
for( it = v.begin(); it != v.end(); it++ )
{
if( it != v.begin() ) os << ", ";
os << *it;
}
return os << "}";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v )
{
os << "[";
typename set< T > :: const_iterator it;
for ( it = v.begin(); it != v.end(); it++ )
{
if( it != v.begin() ) os << ", ";
os << *it;
}
return os << "]";
}
template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v )
{
os << "[";
typename map< F , S >::const_iterator it;
for( it = v.begin(); it != v.end(); it++ )
{
if( it != v.begin() ) os << ", ";
os << it -> first << " = " << it -> second ;
}
return os << "]";
}
char s[30];
int n , p;
int main()
{
ft{
char s1[100];
int k = 0 , l , j = 0;
cin >> n >> p;
for(char i = 65; i <= 90; i++)
{
s1[k] = i;
k++;
if(k == n)
break;
}
s1[k] ='\0';
l= strlen(s1);
printf("Case %d:\n",c);
sort(s1, s1 + l);
j = 0;
do{
cout<<s1<<endl;
j++;
}while(next_permutation(s1 , s1 + l)and j < p);
}
}