20251030 baekjoon
This commit is contained in:
parent
9eddff8b99
commit
53931866bc
52
code_study/Baekjoon/c/1918.c
Normal file
52
code_study/Baekjoon/c/1918.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
1
code_study/Baekjoon/python/4999.py
Normal file
1
code_study/Baekjoon/python/4999.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
print("go" if (lambda s1, s2: s2 in s1)(input(), input()) else "no")
|
||||||
Loading…
x
Reference in New Issue
Block a user