-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path10460.cpp
More file actions
35 lines (29 loc) · 804 Bytes
/
10460.cpp
File metadata and controls
35 lines (29 loc) · 804 Bytes
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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int t, n, ind[40];
string in;
vector<char> ans;
/*
* The idea for this algorithm is to figure out what is the ending index for each
* given character. We start from the very end, we know that the character at the
* very end will be in position (n - 1) % str.size(). From there we insert characters
* on the answer vector. Frankly, I don't fully understand this.
*/
int main() {
cin >> t;
while (t--) {
cin >> in >> n; n--;
ans.clear();
for (int i = in.size(); i > 0; i--) {
ind[i - 1] = n % i;
n /= i;
}
for (int i = 0; i < in.size(); i++)
ans.insert(ans.begin() + ind[i], in[i]);
for (int i = 0; i < ans.size(); i++) cout << ans[i];
cout << endl;
}
return 0;
}