-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5658.cpp
More file actions
72 lines (56 loc) Β· 1.03 KB
/
Copy path5658.cpp
File metadata and controls
72 lines (56 loc) Β· 1.03 KB
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
#include <string>
#include <iostream>
#include <map>
#define MAX 28
using namespace std;
string sol(string str, int n, int k){
map<string, int> words;
int side = n/4;
for(int i=0; i<side; i++){
int j;
for(j=0; j<n; ){
int k;
string str_4N = "";
for(k=j; k<j+side; k++){
str_4N += str[k];
}
if(words[str_4N] != 1)
words[str_4N] = 1;
j += side;
}
char temp = str[n-1];
char prev = str[0];
for(j=1; j<n; j++){
int curr = str[j];
str[j] = prev;
prev = curr;
}
str[0] = temp;
}
int size = words.size();
int cnt = 1;
for(auto it = words.begin(); it != words.end(); it++){
if((size-k+1) == cnt)
return it->first;
cnt++;
}
}
int main(int argc, char const *argv[])
{
int t;
cin>>t;
for(int testcase=0; testcase<t; testcase++){
int n,k;
cin>>n>>k;
string str;
cin>>str;
string ans;
ans = sol(str,n,k);
char F[MAX];
for(int i=0; i<n/4; i++)
F[i] = ans[i];
int nDec = (int)strtol(F, NULL, 16);
cout<<"#"<<testcase+1<<" "<<nDec<<endl;
}
return 0;
}