#include <stdio.h> int youxian(char a) { if(a==‘+‘||a==‘-‘) return 1; if(a==‘*‘||a==‘%‘) return 2; } int main(void) { char stack[20]; int jishu=0; char b; while((b=getchar())!=‘\n‘) { if(b>=33&&b<=47) { if(jishu==0) { stack[jishu]=b; jishu++; } else { if(youxian(stack[jishu-1])>=youxian(b)) { printf("%c",stack[jishu-1]); stack[jishu-1]=b;} else stack[jishu++]=b; } } else printf("%c",b); } while(jishu>0) { printf("%c",stack[jishu-1]); jishu--; } }
时间: 2024-10-24 09:29:48