-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSKMP.java
executable file
·66 lines (61 loc) · 1.41 KB
/
SKMP.java
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
package testJava;
/**
*
* @author Mustansir
*def cn(a):
return ord(a)-ord('a')
for _ in range(int(input())):
s = input()
p = input()
d, n, m = [0]*26, len(s), len(p)
ans, a1, a2 = "", p[0], p[m-1]
for i in range(n):
d[cn(s[i])] += 1
if len(p) == 1:
ans = ""
for i in range(26):
while d[i] > 0:
ans += chr(i+ord('a'))
d[i] -= 1
print(ans)
continue
for i in range(m):
d[cn(p[i])] -= 1
b = False
if cn(a1) > cn(min(p)):
b = True
for i in range(26):
while d[i] != 0:
ans += chr(i+ord('a'))
d[i] -= 1
'''
d1 = []
for i in range(n):
t = ans[0:i]+p+ans[i:]
d1.append(t)
print(min(d1))
'''
n, i = len(ans), 0
while ans[i] == 'a':
i += 1
while i < n and cn(ans[i]) < cn(a1):
i += 1
if b:
# print(0)
d = []
while i < n and cn(ans[i]) <= cn(a1):
d.append(ans[0:i]+p+ans[i:])
i += 1
d.append(ans[0:i]+p+ans[i:])
print(min(d)) # , d)
else:
# print(1)
while i < n and cn(ans[i]) <= cn(a1):
i += 1
print(ans[0:i]+p+ans[i:])
*/
public class SKMP {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}