한시간 넘겨서 풀이봄..ㅠ
일단 예시에는 a*b 이렇게 있는데 이게 항상 한글자만 들어오는것은 아니라는 건 캐치함.
여기 보면은 여러개라고있어서 긴가민가 했는데 일단 문제대로 해석을 할려고함.
강의 듣다가 아차... 싶었다
내가 평소에 잘 안쓰는
substr이라던지 reverse이런거 떠올리질 못함...
그리고 얼마나 애송이 인지 다시한번 알게됨.
또한 반례를 생각해야한다.
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define endl "\n"
int n;
string m;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
cin >> m;
string f, b;
f = m.substr(0, m.find("*"));
b = m.substr(m.find("*") + 1);
for (int i = 0; i < n; ++i)
{
string c;
cin >> c;
if (f.size() + b.size() > c.size())
{
cout << "NE" << endl;
continue;
}
else
{
string cf = c.substr(0, f.size());
string cb = c.substr(c.size() - b.size());
if (cf == f && cb == b) cout << "DA" << endl;
else cout << "NE" << endl;
}
}
return 0;
}
if (pre.size() + suf.size() > s.size())
std::cout << "NE" << "\n";
이거 왜 있는 거임?
ab라는 반례가 생기기 때문이다.
접두사 + 접미사 크기보다는 커야됨.
이런 반례가 있기 때문에