算法与数据结构实验题 3.9 文档

    科技2025-11-07  13

    算法与数据结构实验题 3.9 文档

    题解 撤销:撤销最近的一次的恢复和输入 恢复:恢复最近一次的撤销 但输入之前的撤销不可以 输入 建立栈word 输入和恢复//用数组建立的原因是要输出 建立栈del被撤销的输入在这里

    #include<bits/stdc++.h> using namespace std; stack<string>del; int main() { int top=-1; string str; string word[1000]; int n; cin>>n; while(n--) { cin>>str; if(str=="input") { cin>>str; word[++top]=str; del=stack<string>();//输入操作之前的操作不能恢复了 } else if(str=="ctrl+z")//撤销 { if(top==-1) continue; else { del.push(word[top--]); } } else if(str=="ctrl+y")//恢复 { if(!del.empty()) { word[++top]=del.top(); del.pop(); } } } if(top==-1) { cout<<"No output"<<endl; } else { for(int i=0;i<=top;i++){ cout << word[i] << " "; } } }
    Processed: 0.014, SQL: 9