zoukankan      html  css  js  c++  java
  • 718 银行业务队列简单模拟 (25分)

    挺简单的用队列求解的一题,难度不大。

    输出格式要注意。

      1 #include <iostream>
      2 #include <string>
      3 #include <cstring>
      4 using namespace std;
      5 
      6 class queue_
      7 {
      8 public:
      9     queue_() :f(-1), r(-1)
     10     {
     11         memset(s, 0, 10000 * sizeof(int));
     12     }
     13     ~queue_() {}
     14     void push(int i)
     15     {
     16         s[++r] = i;
     17     }
     18     int pop()
     19     {
     20         return s[++f];
     21     }
     22 public:
     23     int f;
     24     int r;
     25     int s[10000];
     26 };
     27 
     28 void print_(queue_ a, queue_ b)
     29 {
     30     while (a.r != a.f && b.r != b.f)
     31     {
     32         if (a.f < a.r)
     33         {
     34             if(a.f + 1==a.r && b.f==b.r)
     35             cout << a.pop();
     36             else
     37             cout << a.pop() << " ";
     38         }
     39         else
     40         {
     41             break;
     42         }
     43         if (a.f < a.r )
     44         {
     45             if(a.f + 1== a.r && b.f==b.r)
     46             cout << a.pop();
     47             else
     48             cout << a.pop() << " ";
     49         }
     50         else
     51         {
     52             break;
     53         }
     54         if (b.f < b.r)
     55         {
     56             if(b.f + 1== b.r && a.f==a.r)
     57             cout << b.pop();
     58             else
     59             cout << b.pop() << " ";
     60         }
     61         else
     62         {
     63             break;
     64         }
     65     }
     66     if (a.f >= a.r)
     67     {
     68         while (b.f < b.r)
     69         {
     70             if(b.f + 1== b.r)
     71             cout << b.pop();
     72             else
     73             cout << b.pop() << " ";
     74         }
     75     }
     76     else
     77     {
     78         while (a.f < a.r)
     79         {
     80             if(a.f + 1== a.r)
     81             cout << a.pop();
     82             else
     83             cout << a.pop() << " ";
     84         }
     85     }
     86 }
     87 int main()
     88 {
     89     int n;
     90     queue_ a, b;
     91     cin >> n;
     92     for (int i = 0; i < n; i++)
     93     {
     94         int temp;
     95         cin >> temp;
     96         if (temp % 2 == 0)
     97         {
     98             b.push(temp);
     99         }
    100         else
    101         {
    102             a.push(temp);
    103         }
    104 
    105     }
    106     print_(a, b);
    107     return 0;
    108 }
  • 相关阅读:
    CentOS7安装Oracle 11gR2 安装
    CentOS7 FTP服务搭建(虚拟用户访问FTP服务)
    .NET中RabbitMQ的使用
    ElasticSearch(站内搜索)
    SignalR 2.1 简单入门项目
    Oracl基础知识(一)
    CentOS6—HAProxy安装与配置
    Redis C#缓存的使用
    CentOS6— Redis安装(转和延续)
    Linux(CentOS)常用操作指令(二)
  • 原文地址:https://www.cnblogs.com/2020R/p/12389765.html
Copyright © 2011-2022 走看看