티스토리 뷰
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string.h>
using namespace std;
const int INF = 987654321;
int main()
{
int m, n;
bool isConnected[26][26] = { false, };
scanf("%d %d", &m, &n);
for (int i = 0; i < m; i++) {
char a, b;
getchar();
scanf("%c %c", &a, &b);
int s = a - 'a', e = b - 'a';
isConnected[s][e] = true;
}
for (int k = 0; k < 26; k++) {
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
if (isConnected[i][k] && isConnected[k][j])
isConnected[i][j] = true;
}
}
}
for (int iter = 0; iter < n; iter++) {
char str_a[51], str_b[51];
getchar();
scanf("%s %s", &str_a, &str_b);
int len_a = strlen(str_a), len_b = strlen(str_b);
bool isPossible = true;
if (len_a != len_b)
isPossible = false;
else {
for (int i = 0; i < len_a; i++) {
int s = str_a[i] - 'a', e = str_b[i] - 'a';
if (s == e) continue;
if (!isConnected[s][e]) {
isPossible = false;
break;
}
}
}
printf("%s\n", isPossible ? "yes" : "no");
}
return 0;
}
'백준 문제풀이' 카테고리의 다른 글
백준[baekjoon] 8462 (0) | 2020.05.27 |
---|---|
백준[baekjoon] 14728 (0) | 2020.05.02 |
백준[baekjoon] 12865 (0) | 2020.04.20 |
백준[baekjoon] 10165 (0) | 2020.02.26 |
백준[baekjoon] 1390 (0) | 2020.01.19 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 브레젠험 알고리즘
- 백준 27469
- 초등부
- DP
- C++게임개발
- C++게임
- 백준 2365
- unreal enigne
- BOJ 27469
- 정보올림피아드
- pygame
- Python
- 퀸 움직이기
- ndisplay
- 언리얼 프로젝트 재생성 자동화
- 언리얼 자동화
- 언리얼 프로젝트 재생성
- opengl
- Codeforces
- 홍정모의 게임 만들기 연습 문제 패키지
- 숫자판 만들기
- 코드포스
- 테트리스
- BOJ 2365
- 백준
- OpenVDB
- UE5.3
- tetris
- ICPC 후기
- Unreal Engine
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함