// Demo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main()
{
string s = "(((a+b)*c)/(d+c))?(b+c)";
stack<char> st;
int i = 0;
while (i < s.size()) {
st.push(s[i]);
if (s[i] == ')') {
while (st.top() != '(') {
st.pop();
}
st.pop();
st.push('*');
}
++i;
}
while (!st.empty()) {
cout << st.top() << endl;
st.pop();
}
return 0;
}
C++ primer exercise 9.52 parenthesized
最新推荐文章于 2020-10-29 23:15:52 发布