# 생각
find와 substr을 잘 활용하여 문자열의 앞뒤를 잘 비교해준다
입력받은 문자열이 패턴문자열의 접두사 접미사 길이 합보다 크거나 같아야 한다는 조건을 충족해야한다
# 전체 코드
#include <bits/stdc++.h>
using namespace std;
void fastIO() { ios::sync_with_stdio(false); cin.tie(nullptr); }
int main()
{
fastIO();
int n;
cin >> n;
string s;
cin >> s;
int pos = s.find('*');
string prefix, sufix;
prefix = s.substr(0, pos);
sufix = s.substr(pos + 1);
for (int i = 0; i < n; i++)
{
string tmp;
cin >> tmp;
int tsz = tmp.size(), psz = prefix.size(), ssz = sufix.size();
if (psz + ssz > tsz)
{ // 패턴문자열 보다 작으면 일치하지 않는 것
cout << "NE\n";
}
else
{
if (prefix == tmp.substr(0, psz) and sufix == tmp.substr(tsz - ssz))
{
cout << "DA\n";
}
else
{
cout << "NE\n";
}
}
}
}
https://www.acmicpc.net/problem/9996
'Algorithm > BOJ' 카테고리의 다른 글
[BOJ] 1620_나는야 포켓몬 마스터 이다솜.cpp (0) | 2022.05.29 |
---|---|
[BOJ] 2559_수열.cpp (0) | 2022.05.29 |
[BOJ] 11655_ROT 13.cpp (0) | 2022.05.28 |
[BOJ] 1159_농구 경기.cpp (0) | 2022.05.28 |
[BOJ] 10988_팰린드롬인지 확인하기.cpp (0) | 2022.05.28 |