-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexographics-permutations.cpp
51 lines (48 loc) · 1.08 KB
/
lexographics-permutations.cpp
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
ll t;
cin >> t;
ll v = 1;
for(ll i = 1; i <=12 ; i++)
v *= i;
while( t-- )
{
string s= "abcdefghijklm";
bool visited[13] = {0};
string ans = "";
ll n;
cin >> n;
n--;
ll temp = v;
ll k = 12;
for(int i = 0 ; i< 13 ; i ++)
{
ll z = n / temp;
int count = 0;
int j = 0;
while(count <= z && j < 13)
{
if(!visited[j])
{
if(count == z)
{
visited[j] = true;
break;
}
count ++;
}
j++;
}
ans += s[j];
n -= (n / temp) * temp;
if( k != 0)
temp = temp / k;
k--;
}
cout << ans << endl;
}
return 0;
}