PS
BOJ 9996 : 한국이 그리울 땐 서버에 접속하지
lickelon
2025. 1. 27. 16:22
- 문제 링크 : boj.kr/9996
- 난이도 : S3
- 태그 : 문자열, 정규표현식
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
string pat;
cin >> pat;
string new_pat = pat.substr(0, pat.find("*")) + ".*" + pat.substr(pat.find("*")+1);
regex re(new_pat);
for(int i = 0; i < n; i++) {
string s;
cin >> s;
cout << (regex_match(s, re) ? "DA" : "NE") << "\n";
}
return 0;
}
풀이
주어진 패턴 문자열을 알맞은 정규표현식으로 바꾸어 준 뒤, std의 regex를 이용해준다.
728x90