Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- DFS
- 재귀
- 다이나믹 프로그래밍
- 누적 합
- ue5
- 스택
- BFS
- 수학
- 투 포인터
- 백준
- 브루트포스
- 다익스트라
- 자료구조
- 알고리즘
- 시뮬레이션
- c++
- 그리디 알고리즘
- 트리
- 백트래킹
- 우선순위 큐
- Unreal Engine 5
- Team Fortress 2
- 그래프
- 정렬
- 유니온 파인드
- 구현
- 문자열
- VR
- XR Interaction Toolkit
- 유니티
Archives
- Today
- Total
1일1알
백준 9996번 한국이 그리울 땐 서버에 접속하지 C++ 본문
패턴은 * 한개와 알파벳들로 이루어져 있고, * 은 문자열의 시작과 끝에 있지 않기 때문에
무조건 ~~~*~~~ 이런 형태로 이루어져 있다는것을 알 수 있다.
그렇기 때문에 파일과 패턴을 맨 앞부터 * 전까지 비교하고, 맨 뒤부터 * 뒤까지 비교해서 하나라도 다르면 일치하지 않는다.
그리고 고려해야될게 하나 더 있는데, 만약 패턴이 abc*abdef 이고, 파일이 abcdef 라면 위의 비교에서는 전부 같지만, 일치하지는 않는 파일이다.
그렇기 때문에 패턴의 길이 - 1 (*이 있어서 1을 빼줌) 는 파일의 길이보다 작거나 같아야 한다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int n;
string pattern;
vector<string> strs(100);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> pattern;
int idx = 0;
int front = 0;
int back = 0;
while (pattern[idx] != '*') {
front++;
idx++;
}
back = pattern.length() - front - 1;
for (int i = 0; i < n; i++) {
cin >> strs[i];
}
for (int i = 0; i < n; i++) {
bool isSame = true;
for (int j = 0; j < front; j++) {
if (strs[i][j] != pattern[j]) isSame = false;
}
for (int j = 0; j < back; j++) {
if (strs[i][strs[i].length() - 1 - j] != pattern[pattern.length() - 1 - j]) isSame = false;
}
if (pattern.length() - 1 > strs[i].length()) isSame = false;
if (isSame) cout << "DA";
else cout << "NE";
cout << "\n";
}
};
'알고리즘' 카테고리의 다른 글
백준 1941번 소문난 칠공주 C++ (0) | 2022.01.09 |
---|---|
백준 7490번 0 만들기 C++ (0) | 2022.01.08 |
백준 2303번 숫자 게임 C++ (0) | 2022.01.08 |
백준 15683번 감시 C++ (0) | 2022.01.07 |
백준 14891번 톱니바퀴 C++ (0) | 2022.01.06 |