# 자료구조 # deque
어떤 자료구조를 사용하느냐에 따라서
얼마나 코드를 짜야 할 지가 정해질꺼 같다.
실수 했었던 점은 문자열 제거 이후 cur를 무조건 0으로 하였다는 점!
#include <iostream> #include <stdio.h> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <math.h> #include <queue> #include <set> #include <map> #include <list> #include <utility> #include <climits> #include <functional> #define MAX 1000005 #define INF 987654321 #define MOD 1000000 #pragma warning(disable:4996) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<float, float> pf; char ch,pang[45]; int len,cur=0; deque<char> dq; void my_erase(int in) { for(int i=0;i<in;i++) dq.pop_back(); } // 폭발 문자열 제거 void my_move(int in) { for(int i=0;i<in;i++) { if(dq.back()=='.') break; dq.push_front(dq.back()); dq.pop_back(); } } // 폭발 문자열 제거 이후 앞 문자열 확인 int main() { scanf("%c",&ch); while(ch!='\n') { dq.push_back(ch); scanf("%c",&ch); } dq.push_back('.'); scanf("%s",pang); len=strlen(pang); // 입력을 받는다. while(dq.front()!='.') { if(dq.front()==pang[cur]) cur++; else if(dq.front()==pang[0]) cur=1; else cur=0; dq.push_back(dq.front()); dq.pop_front(); if(len==cur) { my_erase(len); my_move(len-1); } } dq.pop_front(); if(dq.empty()) { printf("FRULA"); return 0; } while(!dq.empty()) { printf("%c",dq.front()); dq.pop_front(); } return 0; }
'IT > BOJ' 카테고리의 다른 글
백준(BOJ) 15808 주말 여행 계획 ** (0) | 2018.06.28 |
---|---|
백준(BOJ) 10800 컬러볼 ** (0) | 2018.06.28 |
백준(BOJ) 3392 화성지도 *** (0) | 2018.06.22 |
백준(BOJ) 13547 수열과 쿼리5 *** (0) | 2018.06.22 |
백준(BOJ) 9938 방청소 *** (0) | 2018.06.18 |