题解分享
题解分享简介
队列 - 题解
include
using namespace std;
int main() {
int n;
cin >> n;
queue
q;
for (int i = 0; i
> c;
q.push(c);
}
while (!q.empty()) {
cout << q.front();
q.push(q.front());
q.pop();
q.pop();
}
return 0;
}
//模拟就可以了;
查看全文
0
0
1
2
队列 - 题解
```
#include <iostream>
#include <queue>
using namespace std;
int main() {
queue<char> q;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
char x;
cin >> x;
q.push(x);
}
while (!q.empty()) {
char a = q.front();
q.push(a);
cout << a;
q.pop();
q.pop();
}
return 0;
}
```
查看全文
0
0
0
3
队列 - 题解
```
/*
思路分析
1. 四个步骤作为循环体,直至队列为空
//动态数组法
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
cin.ignore();
vector<char> str;
//getline(cin , str);
char c;
for ( int i = 0; i < n; i++ ) {
cin >> c;
str.push_back(c);
//cout << str[i] << endl;
}
while( !str.empty() ) {
//输出队首元素。(输出,不是出队)
cout << str[0];
//把队首元素插入到队尾。
str.push_back(str[0]);
//删除队首元素。(出队) erase()函数
str.erase(str.begin());
//再次删除队首元素。(出队)
str.erase(str.begin());
}
return 0;
}
//队列法
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
cin.ignore();
queue<char> q;
string str;
getline(cin , str);
for (char c : str ) {
if ( c != ' ' ) {
q.push(c);
}
}
while ( !q.empty() ) {
//q.front() 访问首位
char front = q.front();
cout << front;
//插到队尾
q.push(front);
//删除首位 q.pop() 只能删除首位
q.pop();
//再次删除首位
q.pop();
}
return 0;
}
*/
```
查看全文
0
0
0
2



