// 0943.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <string> #include <iostream> #include <stack> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { string strExpresstion; stack<char> charStack; stack<int> posStack; cout << "Enter the expression please:"; cin >> strExpresstion; for (string::iterator iter = strExpresstion.begin();iter != strExpresstion.end();iter++) { charStack.push(*iter); if (*iter == ')') { while (charStack.top()!='(') charStack.pop(); charStack.pop(); charStack.push('@'); } } while (!charStack.empty()){ cout << charStack.top() << " "; charStack.pop(); } return 0; }