求助,只过了一个测试集

P1449 后缀表达式

waibiba卜 @ 2021-07-06 18:45:42

#include<iostream>
#include<stack>
#include<stdio.h>
using namespace std;
int main()
{
    int num;
    int n1,n2,n3;
    char ch;
    stack<int> s1;
    while((ch=getchar())!='@')
    {
        if(ch>='0'&&ch<='9')
        {
            num*=10;num+=ch-'0';continue;
        }
        else if(ch=='.')
        {
            s1.push(num);
            num=0;continue;
        }
        else 
        {
            n1=s1.top();
            s1.pop();
            n2=s1.top();
            s1.pop();
            if(ch=='+')
            n3=n1+n2;
            else if(ch=='-')
            n3=n2-n1;
            else if(ch=='*')
            n3=n1*n2;
            else if(ch=='/')
            n3=n2/n1;
            s1.push(n3);continue;
        }
    }
    cout<<s1.top();
    return 0;
 } 

by 米特索龙 @ 2021-07-06 19:05:23

这泽莫跳出while 啊


by waibiba卜 @ 2021-07-06 20:54:45

输入一行字符串回车结束getchar读到@就会跳出来啊


|