题目:
思路分析:
简单的栈和队列的模拟!
第一个代码不知道哪里错了 只有20分 附上 希望有人帮忙发现(感谢大佬们!
代码实现:
/*
*@Author: GuoJinlong
*@Language: C++
*/
//#include <bits/stdc++.h>
/*
* __----~~~~~~~~~~~------___
* . . ~~//====...... __--~ ~~
* -. \_|// |||\\ ~~~~~~::::... /~
* ___-==_ _-~o~ \/ ||| \\ _/~~-
* __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~
* _-~~ .=~ | \\-_ '-~7 /- / || \ /
* .~ .~ | \\ -_ / /- / || \ /
* / ____ / | \\ ~-_/ /|- _/ .|| \ /
* |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\
* ' ~-| /| |-~\~~ __--~~
* |-~~-_/ | | ~\_ _-~ /\
* / \ \__ \/~ \__
* _--~ _/ | .-~~____--~-/ ~~==.
* ((->/~ '.|||' -_| ~~-/ , . _||
* -_ ~\ ~~---l__i__i__i--~~_/
* _-~-__ ~) \--______________--~~
* //.-~~~-~_--~- |-------~~~~~~~~
* //.-~~~--\
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* 神兽保佑 永无BUG
*/
const int MAX=10100;
string ss[MAX];
int n,m,s;
stack<char>st;
queue<char>qu;
int main(){
cin>>n>>m>>s;
for(int i=1;i<=n;i++){
cin>>ss[i];
}
int x;
while (cin>>x&&x!=-1) {
if(x==0){
if(st.size()==0) continue;
else {
char c=st.top();
st.pop();
qu.push(c);
}
}
else {
if(st.size()==s){
char c=st.top();
st.pop();
qu.push(c);
}
if(ss[x].length()==0) continue;
string ans;
string str=ss[x];
for(int j=1;j<str.length();j++){
ans+=str[j];
}
ss[x]=ans;
st.push(str[0]);
}
}
while (!qu.empty()) {
char c=qu.front();
qu.pop();
cout<<c;
}
}
/*
*@Author: GuoJinlong
*@Language: C++
*/
//#include <bits/stdc++.h>
/*
* __----~~~~~~~~~~~------___
* . . ~~//====...... __--~ ~~
* -. \_|// |||\\ ~~~~~~::::... /~
* ___-==_ _-~o~ \/ ||| \\ _/~~-
* __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~
* _-~~ .=~ | \\-_ '-~7 /- / || \ /
* .~ .~ | \\ -_ / /- / || \ /
* / ____ / | \\ ~-_/ /|- _/ .|| \ /
* |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\
* ' ~-| /| |-~\~~ __--~~
* |-~~-_/ | | ~\_ _-~ /\
* / \ \__ \/~ \__
* _--~ _/ | .-~~____--~-/ ~~==.
* ((->/~ '.|||' -_| ~~-/ , . _||
* -_ ~\ ~~---l__i__i__i--~~_/
* _-~-__ ~) \--______________--~~
* //.-~~~-~_--~- |-------~~~~~~~~
* //.-~~~--\
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* 神兽保佑 永无BUG
*/
#include<bits/stdc++.h>
#include<queue>
#include<stack>
using namespace std;
int main() {
int n,m,s,i,j;
queue <char> a[101];
cin>>n>>m>>s;
char ch;
for(i=0; i<n; i++) {
for(j=0; j<m; j++) {
cin>>ch;
a[i].push(ch);
}
}
int b;
stack <char> c1;
queue <char> c2;
while(cin>>b) {
if(b==-1) {
break;
}
if(b!=0) {
if(a[b-1].size()>0) {
if(c1.size()>=s) {
c2.push(c1.top());
c1.pop();
}
c1.push(a[b-1].front());
a[b-1].pop();
}
} else {
if(c1.size()>0) {
c2.push(c1.top());
c1.pop();
}
}
}
int size=c2.size();
for(i=0; i<size; i++) {
cout<<c2.front();
c2.pop();
}
}