20251001 baekjoon
This commit is contained in:
parent
ad7f723b17
commit
9a209363fe
47
code_study/Baekjoon/c/9935.c
Normal file
47
code_study/Baekjoon/c/9935.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
bool isBoom(char* stack, char* boom, int top, int lenB);
|
||||||
|
void printStack(char* stack, int top);
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
char str[1000001];
|
||||||
|
char stack[1000001];
|
||||||
|
char boom[36];
|
||||||
|
int top = -1;
|
||||||
|
|
||||||
|
scanf("%s",str);
|
||||||
|
int len = strlen(str);
|
||||||
|
scanf("%s",boom);
|
||||||
|
int lenB = strlen(boom);
|
||||||
|
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
stack[++top] = str[i];
|
||||||
|
if (top + 1 >= lenB && isBoom(stack, boom, top, lenB)) {
|
||||||
|
top -= lenB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printStack(stack, top);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isBoom(char* stack, char* boom, int top, int lenB) {
|
||||||
|
for (int i=0; i<lenB; i++) {
|
||||||
|
if (stack[top-lenB+i+1] != boom[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printStack(char* stack, int top) {
|
||||||
|
if (top == -1) printf("FRULA\n");
|
||||||
|
else {
|
||||||
|
for (int i=0; i<=top; i++) printf("%c", stack[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user