dalao们帮我看一下,哪错了???
查看原帖
dalao们帮我看一下,哪错了???
436123
_CC_lld楼主2021/7/7 16:19

我用这段代码在dev-c++上试了, 输入输出完全一样,可洛谷上为什么是0分???

#include <bits/stdc++.h>
using namespace std;

string s;
int stk[505], s1 = 0, tot = 0;

int main () {
	cin >> s;
	
	for (int i = 0; i < s.length(); ++ i) {
		
		if (s[i] >= '1' && s[i] <= '9') {
			s1 = s1 * 10 +  (s[i] - '0');
	    }

    	else if (s[i] == '.') {
    		stk[++ tot] = s1;
    		s1 = 0; 
    	}
			
    	else {
    		if (s[i] == '+') {
    		    stk[-- tot] = stk[tot] + stk [tot + 1];
    	    }
    			    
    		if (s[i] == '-') {
    		    stk[-- tot] = stk[tot] - stk [tot + 1];
    		}
			    
    		if (s[i] == '*') {
    		    stk[-- tot] = stk[tot] * stk [tot + 1];
    		}
			    
    		if (s[i] == '/') {
    		    stk[-- tot] = stk[tot] / stk [tot + 1];   
    		}
      	}
	}
	
	cout << stk[tot];
	
	return 0; 
}
2021/7/7 16:19
加载中...