// 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; }