Skip to content

Commit 0d497b3

Browse files
committed
#26 : 15723_n단 논법
1 parent d5e1450 commit 0d497b3

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

이티준희/15723_n단 논법.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#2023-05-18-Week6-과제
2+
#15723_n단 논법
3+
4+
'''
5+
n개의 전제가 있을 때 m개의 결론을 도출
6+
7+
입력 :
8+
정수 n(2 ≤ n ≤ 26)
9+
둘째 줄부터 n개의 줄에 걸쳐 각 줄에 전제가 하나씩
10+
a is b의 형식
11+
a는 b이면서 c일 수 없으나, a와 b가 동시에 c일 수는 있다.
12+
13+
출력 :
14+
m개의 줄에 걸쳐 각 줄에 결론이 참인지 거짓인지
15+
'''
16+
17+
18+
#런타임 에러 발생
19+
20+
import sys
21+
input = sys.stdin.readline()
22+
23+
N = int(input())
24+
graph = [[0] * 26 for i in range(26)]
25+
26+
27+
#입력한 알파벳 순서를 어떻게 정해야할까.............
28+
order = "abcdefghijklmnopqrstuvwxyz" #알파벳 문자열의 인덱스로..?
29+
30+
31+
for i in range(N) :
32+
a, b = map(order.index, input().strip().split(" is "))
33+
graph[a][b] = 1
34+
35+
for i in range(N) :
36+
for j in range(N) :
37+
for k in range(N) :
38+
if graph[j][k] < graph[j][i] + graph[i][k] :
39+
graph[j][k] = graph[j][k]
40+
else :
41+
graph[j][k] = graph[j][i] + graph[i][k]
42+
43+
M = int(input())
44+
45+
for i in range(M) :
46+
a, b = map(order.index, input().strip().split(" is "))
47+
if graph[a][b] != 0 :
48+
print('T')
49+
else :
50+
print('F')

0 commit comments

Comments
 (0)