๐ฆ ๋น์ทํ ๋จ์ด
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
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
N = int(input())
words = []
length = 30000
for i in range(N):
word = input()
words.append(word)
S = -1
T = -1
max_count = -1
for i in range(N):
left = words[i]
for j in range(i + 1, N):
right = words[j]
count = 0
length = min(len(left), len(right))
if left == right or left[0] != right[0]:
continue
for k in range(length):
if left[k] != right[k]:
break
count += 1
# ์ต๋ ์ ๋์ฌ ๊ฐฑ์
if max_count < count:
max_count = count
S = i
T = j
# ์์์ ๋ถํฐ ์ต๋ ์ ๋์ฌ๋ฅผ ๊ฐ์ง๊ณ ์ฐพ์
print(words[S])
print(words[T])
3. ํด์ค
pypy3
112490kb
3136ms
ํด์ค
๋์ ๋๋ฆฌ๋ก ์ต์ ํํ๋ค๊ฐ ์๊พธ ํ๋ ค์ O(N^2)๋ก ์์ โฆ.
๋ฌธ์์ด์ ์์ ํ์ํ์ฌ ์ต๋ ์ ๋์ฌ ๊ธธ์ด๋ฅผ ๊ฐฑ์ ํ๊ณ ์ธ๋ฑ์ค๋ฅผ ์ ์ฅ
๊ตฌํ ์ธ๋ฑ์ค๋ฅผ ์ต์ข ์ผ๋ก ์ถ๋ ฅ
This post is licensed under CC BY 4.0 by the author.