[백준 9935번]문자열 폭발
2017. 7. 28. 03:15ㆍ알고리즘/백준
반응형
소스코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <iostream> using namespace std; char word[1000001],fire[37],st[1000001]; int word_length = 0, fire_length = 0,sp=0; void search() { for (int i = 0; i < word_length;i++) { st[sp++] = word[i]; if (word[i] == fire[fire_length-1]) { int cnt=0; for (int j = sp-1,k=fire_length-1; j >= sp - fire_length, k>=0; j--,k--) { if (st[j] == fire[k]) cnt++; } if (cnt == fire_length) sp -= (fire_length); } } } int main() { ios::sync_with_stdio(false); cin >> word; cin >> fire; while (word[word_length++] != NULL); while (fire[fire_length++] != NULL); word_length -= 1; fire_length -= 1; search(); if (sp==0){ cout << "FRULA"; return 0; } for (int i = 0; i < sp; i++) { cout << st[i]; } return 0; } | cs |
반응형
'알고리즘 > 백준' 카테고리의 다른 글
[백준 7490번] 0 만들기 (2) | 2017.08.08 |
---|---|
[백준 1992번] 쿼드트리 (2) | 2017.08.01 |
[백준 2089번] -2진수 (0) | 2017.07.28 |
[백준 9934번] 완전 이진 트리 (0) | 2017.07.27 |
[백준 1182번] 부분집합의 합 (0) | 2017.07.27 |