forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10460.cpp
86 lines (77 loc) · 1.07 KB
/
10460.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
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
#include <bits/stdc++.h>
using namespace std;
int numOfCase;
char str[30];
int str_index;
class MyString
{
public:
char buffer[30];
int len;
public:
MyString();
MyString(char *p);
void Insert(int k, char alpha);
void Print()
{
cout << buffer << endl;
}
};
MyString::MyString()
{
memset(buffer, 0, sizeof(buffer));
len = 0;
}
MyString::MyString(char *p)
{
strcpy(buffer, p);
len = strlen(p);
}
void MyString::Insert(int k, char alpha)
{
if (k > len)
{
return;
}
int i;
buffer[len + 1] = '\0';
for (i = len; i > k; i--)
{
buffer[i] = buffer[i - 1];
}
buffer[k] = alpha;
len++;
}
MyString Solve(int th, int num)
{
if (th == 1)
{
char temp[3];
temp[0] = str[0];
temp[1] = '\0';
MyString ms(temp);
return ms;
}
int a, b;
a = (int)ceil(num * 1.0 / th);
b = num % th;
if (!b)
{
b += th;
}
MyString ms = Solve(th - 1, a);
ms.Insert(b - 1, str[th - 1]);
return ms;
}
int main()
{
cin >> numOfCase;
while (numOfCase--)
{
cin >> str >> str_index;
int len = strlen(str);
MyString ms = Solve(len, str_index);
ms.Print();
}
return 0;
}