Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit b2ddc47

Browse files
authored
Merge pull request #70 from boostcamp-ai-tech-4/humi2
[ํ›„๋ฏธ] 2021.06.10
2 parents 89b6477 + 90d2ac1 commit b2ddc47

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
import re
3+
input = sys.stdin.readline
4+
n= int(input())
5+
for _ in range(n):
6+
string=input().rstrip()
7+
num=int(input())
8+
set_string=set(string) # set์„ ์ด์šฉํ•ด unique ๋ฌธ์ž๋“ค๋งŒ ๊ฐ€์ ธ์˜ด
9+
_max,_min=0,100000
10+
for s in set_string:
11+
match_iters=re.finditer(s, string) # ์ •๊ทœ์‹์„ ์‚ฌ์šฉํ•ด target ์œ„์น˜ ์ฐพ๊ธฐ match_iters => iterater, <_sre.SRE_Match object; span=(1 ์‹œ์ž‘์ , 2 ๋์ ), match='a'>
12+
match_list_idx=[x.start() for x in match_iters] # target์œ„์น˜์˜ ์‹œ์ž‘์ ๋“ค๋งŒ ์ €์žฅ
13+
cnt=0
14+
if len(match_list_idx) >=num: # target์˜ ๊ฐœ์ˆ˜๊ฐ€ num๋ณด๋‹ค ํฌ๋ฉด
15+
while True:
16+
diff=match_list_idx[cnt+num-1]-match_list_idx[cnt] # ์ œ์ผ ์•ž ๊ธ€์ž, ๋’ค๊ธ€์ž์˜ ์ฐจ
17+
if _min>diff:
18+
_min=diff
19+
if _max<diff:
20+
_max=diff
21+
cnt+=1
22+
if cnt+num>len(match_list_idx): #์•ž๊ธ€์ž index ++
23+
break
24+
if _max+_min==100000:
25+
print(-1)
26+
else:
27+
print(_min+1,_max+1)

0 commit comments

Comments
ย (0)