就这么玄学的吗?下载数据,发现结果是对的,但是wa了

P1449 后缀表达式

yuyanggo @ 2019-05-02 10:53:54

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cctype>
using namespace std;

const int maxn = 2e5;
int a[maxn + 10];
char s[maxn];

int main() {
    freopen("input.txt", "r", stdin);

    scanf("%s", s);
    int len = strlen(s);
    a[0] = 0;

    int last = 0;
    for(int i = 0; i < len; i++) {
        if(isdigit(s[i])) {
            last = last * 10 + s[i] - '0';
            continue;
        }
        if(s[i] == '.') {
            a[++a[0]] = last;
            last = 0;
            continue;
        }
        if(s[i] == '-') {
            if(a[0] == 1) {
                a[1] = -a[1];
                continue;
            }
            a[--a[0]] = a[a[0]] - a[a[0] + 1];
            continue;
        }
        if(s[i] == '+') {
            if(a[0] == 1) {
                continue;
            }
            a[--a[0]] = a[a[0]] + a[a[0] + 1];
            continue;
        }
        if(s[i] == '*') {
            a[--a[0]] = a[a[0]] * a[a[0] + 1];
            continue;
        }
        if(s[i] == '/') {
            a[--a[0]] = a[a[0]] / a[a[0] + 1];
            continue;
        }
        if(s[i] == '@') break;
    }
    printf("%d\n", a[1]);
    return 0;
}

by t162 @ 2019-05-02 10:58:28

freopen海星


by Mogu @ 2019-05-02 11:04:11

freopen赛高


by Smile_Cindy @ 2019-05-02 11:06:03

@yuyanggo

把freopen去掉


by Smile_Cindy @ 2019-05-02 11:06:38

@yuyanggo

但还是WA


by Smile_Cindy @ 2019-05-02 11:07:18

hint:最好不要这么写

a[--a[0]] = a[a[0]] - a[a[0] + 1];

by 此ID已被注册 @ 2019-08-03 15:37:49

同问


|