백준 9996 한국이 그리울 땐 서버에 접속하지 C++
- C
- 2023. 3. 30.
백준 9996 한국이 그리울 땐 서버에 접속하지
백준 9996번 "한국이 그리울 땐 서버에 접속하지" 문제의 자세한 내용은 글 하단의 문제 링크를 참고하세요.

9996 문제에 주어지는 입력 및 예시
입력:
3
a*d
abcd
anestonestod
facebook
출력:
DA
DA
NE
코드
백준 9996번 "한국이 그리울 땐 서버에 접속하지" 문제의 코드입니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,pos;
string pattern,tmp;
vector<string> str;
cin>>N>>pattern;
pos=pattern.find("*");
string front=pattern.substr(0,pos);
string rear=pattern.substr(pos+1);//*이니까 하나 더해줌.
for(int i=0;i<N;i++){
cin>>tmp;
int tmpsize=tmp.length();
if(tmpsize<(front.length()+rear.length()))
str.push_back("NE");
else{
if(front==tmp.substr(0,front.length())&&rear==tmp.substr(tmpsize-rear.length()))
str.push_back("DA");
else
str.push_back("NE");
}
}
for(auto v: str) cout<<v<<"\n";
return 0;
}
실행
위의 코드를 예제의 입력을 넣어 실행했을 때의 결과입니다.
https://www.acmicpc.net/problem/9996
9996번: 한국이 그리울 땐 서버에 접속하지
총 N개의 줄에 걸쳐서, 입력으로 주어진 i번째 파일 이름이 패턴과 일치하면 "DA", 일치하지 않으면 "NE"를 출력한다. 참고로, "DA"는 크로아티어어로 "YES"를, "NE"는 "NO"를 의미한다.
www.acmicpc.net
'C' 카테고리의 다른 글
백준 2740 행렬 곱셈 C++ (0) | 2023.03.31 |
---|---|
백준 2559 수열 C++ (0) | 2023.03.30 |
백준 10798 세로읽기 C++ (0) | 2023.03.30 |
백준 2566 최댓값 C++ (0) | 2023.03.30 |
백준 2738 행렬 덧셈 C++ (0) | 2023.03.29 |