From 53931866bc4bcf311bc11ac0860cd0ee16855049 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Thu, 30 Oct 2025 20:49:26 +0900 Subject: [PATCH] 20251030 baekjoon --- code_study/Baekjoon/c/1918.c | 52 ++++++++++++++++++++++++++++++ code_study/Baekjoon/python/4999.py | 1 + 2 files changed, 53 insertions(+) create mode 100644 code_study/Baekjoon/c/1918.c create mode 100644 code_study/Baekjoon/python/4999.py diff --git a/code_study/Baekjoon/c/1918.c b/code_study/Baekjoon/c/1918.c new file mode 100644 index 0000000..d37bd12 --- /dev/null +++ b/code_study/Baekjoon/c/1918.c @@ -0,0 +1,52 @@ +#include +#include + +bool compareTo_priority_op(char op1, char op2) { + int pr1 = op1 == '*' || op1 == '/' ? 2 : op1 == '+' || op1 == '-' ? 1 : 0; + int pr2 = op2 == '*' || op2 == '/' ? 2 : op2 == '+' || op2 == '-' ? 1 : 0; + + return pr1 >= pr2 ? true : false; +} + +int main() { + char input[100]; + scanf("%s",input); + + char op[100]; + int op_top = -1; + char result[100]; + int res_top = -1; + + int idx = 0; + while(input[idx] != '\0') { + char c = input[idx]; + + if('A' <= c && c <= 'Z') { + result[++res_top] = c; + } + else { + if(c=='(') { + op[++op_top] = c; + } + else if(c==')') { + while(op_top != -1 && op[op_top] != '(') { + result[++res_top] = op[op_top--]; + } + if(op_top != -1) op_top--; + } + else { + while(op_top != -1 && compareTo_priority_op(op[op_top], c)) { + result[++res_top] = op[op_top--]; + } + op[++op_top] = c; + } + } + idx++; + } + + while(op_top != -1) result[++res_top] = op[op_top--]; + + for(int i=0; i<=res_top; i++) printf("%c",result[i]); + + return 0; +} diff --git a/code_study/Baekjoon/python/4999.py b/code_study/Baekjoon/python/4999.py new file mode 100644 index 0000000..9445225 --- /dev/null +++ b/code_study/Baekjoon/python/4999.py @@ -0,0 +1 @@ +print("go" if (lambda s1, s2: s2 in s1)(input(), input()) else "no") \ No newline at end of file