#include <iostream> #include <stack> #include <stdlib.h> #include <string.h> #include <stdio.h> using namespace std; stack<char> st; stack<int> stlet; int a, b, k = 0, i, n; void st_oper(char s); bool isNumber(char Symbol); int main() { string s; string s1; cout << "Enter The String For Reverse Polish Notation" << endl; getline(cin, s); for (i = 0; i < s.size(); i++) { k = i; n = 0; if (s[i] == '*') { while (st.size()) { if (st.top() == '+' || st.top() == '-' || st.top() == '(')break; st_oper(st.top()); } st.push(s[i]); } else if (s[i] == '/') { while (st.size()) { if (st.top() == '+' || st.top() == '-' || st.top() == '(')break; st_oper(st.top()); } st.push(s[i]); } else if (s[i] == '+') { while (st.size()) { if (st.top() == '(')break; st_oper(st.top()); } st.push(s[i]); } else if (s[i] == '-') { while (st.size()) { if (st.top() == '(')break; st_oper(st.top()); } st.push(s[i]); } else if (s[i] == '(') { st.push(s[i]); } else if (s[i] == ')') { while (st.size()) { if (st.top() == '(') { st.pop(); break; } st_oper(st.top()); } } else if (isNumber(s[i])) { while (isNumber(s[k])) { if (k == s.size())break; s1[n] = s[k]; n++; k++; } k--; i = k; stlet.push(atoi(s1.c_str())); } //считывает посимвольно } while (st.size())st_oper(st.top()); cout << stlet.top(); } void st_oper(char s) { if (stlet.size() > 1) { a = stlet.top(); stlet.pop(); b = stlet.top(); stlet.pop(); if (s == '+') { b += a; st.pop(); stlet.push(b); } else if (s == '-') { b -= a; st.pop(); stlet.push(b); } else if (s == '*') { b *= a; st.pop(); stlet.push(b); } else if (s == '/') { b /= a; st.pop(); stlet.push(b); } } } bool isNumber(char Symbol) { if (Symbol >= '0' && Symbol <= '9') return true; return false; } With single digits everything works fine, but with double digits, it doesn’t display anything, I’m dumb for a couple of hours, can you tell me a mistake?
if(isNumber(s[i])) { while(isNumber(s[k])) { if(k==s.size())break;s1[n]=s[k];n++;k++; } k--;i=k;stlet.push(atoi(s1.c_str())); }if(isNumber(s[i])) { while(isNumber(s[k])) { if(k==s.size())break;s1[n]=s[k];n++;k++; } k--;i=k;stlet.push(atoi(s1.c_str())); }? - Grundy