https://www.acmicpc.net/problem/15723
문제
3
a is b
b is c
c is d
3
a is d
a is c
d is a
a는 b다. b는 c다. c는 d다.
그럼 a는 d다. (o)
그럼 d는 a다. (x)
풀이
#include <bits/stdc++.h>
using namespace std;
vector<int> alpha(26, -1);
int find(int target, int from)
{
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n;
cin.ignore();
while (n--)
{
string s;
getline(cin, s);
int p, c;
c = s.front();
p = s.back();
alpha[c - 97] = p - 97;
}
cin >> m;
cin.ignore();
while (m--)
{
string s;
getline(cin, s);
int p, target;
p = s.front();
target = s.back();
p -= 97, target -= 97;
while (true)
{
// cout <<
if (alpha[p] == target)
{
cout << "T\n";
break;
}
if (alpha[p] == -1)
{
cout << "F\n";
break;
}
p = alpha[p];
}
}
}
728x90
'백준이당' 카테고리의 다른 글
[C++] 백준 14940번 : 쉬운 최단거리 (0) | 2025.06.04 |
---|---|
[C++] 백준 5014 스타트 링크 (1) | 2025.06.04 |
[C++] 백준 11752번 : 트리의 부모 찾기 (0) | 2025.06.04 |
[C++] 백준 1916번 : 최소비용 구하기 (0) | 2025.06.01 |
[C++] 백준 18352번 : 특정 거리의 도시 찾기 (0) | 2025.05.29 |