-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path문자열 탑 쌓기.cpp
More file actions
39 lines (36 loc) · 877 Bytes
/
문자열 탑 쌓기.cpp
File metadata and controls
39 lines (36 loc) · 877 Bytes
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
33
34
35
36
37
38
39
//
// Created by kayoung on 2022/09/29.
// https://www.acmicpc.net/problem/25643
#include <iostream>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
string top;
cin >> top;
int ans = 1;
for (int i = 0; i < N - 1; i++) {
string input;
cin >> input;
bool can = false;
int comp;
for (int j = 0; j < M && !can; j++) {
comp = top.substr(0, j + 1).compare(input.substr(M - 1 - j, j + 1));
if (comp == 0) {
can = true;
}
}
for (int j = 0; j < M && !can; j++) {
comp = input.substr(0, j + 1).compare(top.substr(M - 1 - j, j + 1));
if (comp == 0) {
can = true;
}
}
if (!can) {
ans = 0;
break;
}
top = input;
}
cout << ans;
}