#include<iostream>
#include<stack>
#include<vector>
using namespace std;
int main()
{
int t;
cin >> t;
vector<string> op(t);//定义容器大小为t
string target;
for (int i = 0; i < t; i++) {
cin >> op[i];
}
cin >> target;
vector<string> s;
int flag = 0;
for(int i = 0; i < t; i++) {
if (target == op[i]) {
flag = 1;
s.push_back(op[i]);//将新元素压入数组的最尾端
break;
}
if (op[i] == "return") {
s.pop_back();
}
else
{
s.push_back(op[i]);
}
}
if (flag == 1) {
for (int i = 0; i < s.size(); i++) {
if (i)cout << "->";
cout << s[i];
}
cout << endl;
}
//如果用原来的stack来实现的话还要在倒过来一边
else {
cout << "Not Found" << endl;
}
return 0;
}
函数的实现(栈)
最新推荐文章于 2024-11-09 20:38:27 发布