why

P1449 后缀表达式

sizhenhualei @ 2024-09-30 10:40:53

只是移动了个--top,为啥就0分


by sizhenhualei @ 2024-09-30 10:45:38

#include <bits/stdc++.h>  
using namespace std; 
#define int long long
char a;int m[111],top=0;
signed main() { 
    int n=0;
    while(cin>>a){
        if(a=='@') break;
        if(a>='0'&& a<='9') n=n*10+a-'0';
        if(a=='.') m[1+top]=n,n=0,top++;
        if(a=='+') m[top-1]=m[top-1]+m[top],top--;
        if(a=='-') m[top-1]=m[top-1]-m[top],top--;
        if(a=='*') m[top-1]=m[top-1]*m[top],top--;
        if(a=='/') m[top-1]=m[top-1]/m[top],top--;
    }
    cout<<m[top];
    return 0;
}

100分


by sizhenhualei @ 2024-09-30 10:46:17

#include <bits/stdc++.h>  
using namespace std; 
#define int long long
char a;int m[111],top=0;
signed main() { 
    int n=0;
    while(cin>>a){
        if(a=='@') break;
        if(a>='0'&& a<='9') n=n*10+a-'0';
        if(a=='.') m[++top]=n,n=0;
        if(a=='+') m[top-1]=m[--top]+m[1+top];
        if(a=='-') m[top-1]=m[--top]-m[1+top];
        if(a=='*') m[top-1]=m[--top]*m[1+top];
        if(a=='/') m[top-1]=m[--top]/m[1+top];
    }
    cout<<m[top];
    return 0;
}

0分


by Civilight_Eterna @ 2024-09-30 10:51:46

你把前面的-1去掉试试


by Civilight_Eterna @ 2024-09-30 10:53:50

这里有运算顺序的问题,m[--top]+m[1+top] 执行完后在执行赋值语句


by Civilight_Eterna @ 2024-09-30 10:54:42

@sizhenhualei


|