3 条题解

  • 1
    @ 2024-4-10 17:55:28

    #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; queue<char> q; for (int i = 0; i < n; i++) { char c; cin >> c; q.push(c); } while (!q.empty()) { cout << q.front(); q.push(q.front()); q.pop(); q.pop(); } return 0; } //模拟就可以了;

    • 0
      @ 2025-4-6 19:20:09
      #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
        @ 2025-3-13 15:00:24
        /*
        思路分析
            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
        上传者