中等-时间限制: 1000MS内存限制: 256MB分数:100OI排行榜得分:16(0.1*分数+2*难度)
队列基础第十一讲(Level2)
描述
大熊和小鹿周末去密室逃脱,桌面上有n张扑克牌是破解密码的关键。每张扑克牌由(A,2,3,4,5,6,7,8,9,J,Q,K)任意一张组成。生成密码的规则如下:
1 第一张扑克牌拿走,第二张扑克牌挪到剩余扑克牌的最后。
2 将第一步一直执行,直到所有扑克牌拿走。
3 拿走的扑克牌顺序,就是逃脱密码。
同学们帮大熊和小鹿破解密码吧。
输入描述
共2行,第一行,一个整数n,表示有n张扑克牌(1<n<50),第二行,n张扑克牌。
输出描述
一行,表示逃脱密码。
样例输入 1
10 A A J 1 2 K 3 7 Q 6
样例输出 1
A J 2 3 Q A K 6 7 1
#include <bits/stdc++.h>
using namespace std;
int main() {
queue<char> s;
char id;
int n;
int k=1;
cin>>n;
for(int i=0;i<n;i++){
cin>>id;
s.push(id);
}
while(s.size()!=0){
if(k % 2==1){
cout<<s.front()<<" ";
s.pop();
}else{
s.push(s.front());
s.pop();
}
k++;
}
return 0;
}