3 条题解
-
0
/* 思路分析 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; } */
- 1
信息
- ID
- 102
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 119
- 已通过
- 67
- 上传者