백준 9996 한국이 그리울 땐 서버에 접속하지 C++

백준 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;
}

실행

위의 코드를 예제의 입력을 넣어 실행했을 때의 결과입니다.

 

'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

Designed by JB FACTORY