// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include "pch.h" #include <iostream> #include<stack> #include <string> using namespace std; int main() { // //std::cout << "Hello World!\n"; //stack<string> words;//初始化 //string str; //cout << "Enter some words (Ctrl +Z to end ):" << endl; //while (cin >> str) //{ // words.push(str);//将数据压栈 //} //while (words.empty() == false) //{ // cout << words.top() << endl;//将数据输出 // words.pop();//输出后进行删除 //} //return 0; stack <char> sta; string str; cin >> str; string::iterator iter = str.begin(); while (iter !=str.end()) { if (*iter != ')') { sta.push(*iter);//取值并将值放入stack } else { while (sta.top() != '(' && !sta.empty()) { sta.pop(); } if (sta.empty()) { cout << "000000000000"; } else { sta.pop(); sta.push('@'); } } ++iter; } while (!sta.empty()) { cout << sta.top() << endl; sta.pop(); } return 0; }