C76-解密QQ
2025-10-07 12:06:59
发布于:江苏
11阅读
0回复
0点赞
一、解密QQ

#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
queue<char> q;
string s;
int main(){
cin >> s;
int len = s.length();
for (int i=0; i<len; i++){
q.push(s[i]);
}
while (!q.empty()){
cout << q.front(); //输出队首
q.pop(); //出队
q.push(q.front());
q.pop();
}
return 0;
}
/*
输入:145328796
输出:152763984
*/
二、鱼的记忆
#include <bits/stdc++.h>
#include <queue>
using namespace std;
queue<char> q;
int n, m, ans;
char t;
//判断字符ch有没有出现,没有返回0, 有则返回1;
bool check(char ch)
{
int idx = 1;
char s[10005] = {}; //临时记忆
while (q.size()){
s[idx++] = q.front();
q.pop();
}
//重新放回到记忆里
for (int i=1; i<idx; i++) q.push(s[i]);
//若存在大脑里则返回1, 否则返回0
for (int i=1; i<idx; i++){
if (s[i] == ch) return 1;
}
return 0;
}
int main()
{
cin >> n >> m;
for (int i=1; i<=n; i++) {
cin >> t;
if (check(t) == 0) {
if (q.size() == m) {
q.pop(); //先弹出队首
}
q.push(t); //再入队
ans++;
}
}
cout << ans;
return 0;
}
/*
输入:
7 3
a b a e d d a
输出:
5
*/
三、周末舞会
#include <bits/stdc++.h>
#include <queue>
using namespace std;
queue<int> q1, q2;
int n, m, t;
int main(){
//1.先将所有的数分别入队
cin >> n >> m >> t;
for (int i=1; i<=n; i++) q1.push(i);
for (int i=1; i<=m; i++) q2.push(i);
while (t--){
printf("%d %d\n", q1.front(), q2.front());
q1.push(q1.front()); q1.pop();
q2.push(q2.front()); q2.pop();
}
return 0;
}
//A2 B3
//1 1
//2 2
//1 3
//2 1
//
//4
四、作业提示
围圈报数
循环嵌套,将前面的m-1个元素往后挪, 第m个输出即可
使用队列最香~
#include <bits/stdc++.h>
#include <queue>
using namespace std;
queue<int> q;
int main(){
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
for(int i=1; i<=m-1; i++) 从队头到队尾{
}
cout << q.front();
q.pop();
return 0;
}
这里空空如也



有帮助,赞一个