-
个人简介
www.xiaodao0.com https://www.beatstage.com/ https://poki.com/
https://suulnnka.github.io/BullshitGenerator/index.html?
int main(){ printf("请输入列表:\n"); sqStack s, q, l; initStack(&s); //存储输入的中缀表达式 initStack(&q); //存储运算符号 initStack(&l); //存储得到后缀表达式 int n, sum = 0,i = 0; char str[10]; char x; char a, b; scanf("%c", &x); while('#' != x){ Push(&s, x); scanf("%c", &x); //将输入的中缀表达式存入栈中 }
int len = StackLen(s); printf("len:%d\n", len); for(int i=0;i<len;i++){ //根据栈的先进后出的规则倒序输出 Pop(&s, &a); printf("a:%c\n", a); if(isdigit(a)){ // 计算后缀表达式 Push(&l, a); } else { if (')' == a) { Push(&q, a); } else if ('(' == a) { Pop(&q, &b); while (')' != b) { Push(&l, b); Pop(&q, &b); } } else if ('+' == a || '-' == a) { if (!StackLen(q)) { Push(&q, a); } else { do { Pop(&q, &b); if (')' == b) { Push(&q, b); } else { Push(&l, b); } } while (b != ')' && StackLen(q)); Push(&q, a); } } else if (a == '*' || a == '/' || a == '(') { Push(&q, a); } } } while (StackLen(q)){ Pop(&q, &b); Push(&l, b); } while (StackLen(l)){ //逆序赎回后缀表达式 Pop(&l, &a); printf("%c ", a); }
}
-
通过的题目
-
最近活动
This person is lazy and didn't join any contests or homework. -
最近编写的题解
This person is lazy and didn't write any solutions.