返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n;
  4. queue<int> q;
  5. int main()
  6. {
  7.         cin>>n;
  8.         int a;
  9.         for(int i=0;i<n;i++)
  10.         {
  11.                 cin>>a;
  12.                 q.push(a);
  13.         }
  14.         while(q.size()>1)
  15.         {
  16.                 int t=q.front();
  17.                 if(t%2==0)
  18.                 {
  19.                         q.push(t);
  20.                         q.pop();
  21.                         q.pop();
  22.                         n--;       
  23.                 }
  24.                 else
  25.                 {
  26.                         q.push(t);
  27.                         q.pop();
  28.                 }
  29.                 /*for(int j:v)
  30.                         cout<<j<<' ';
  31.                 cout<<endl;*/
  32.         }
  33.         /*for(int i:v)
  34.                 cout<<i<<endl;*/
  35.         cout<<q.front()<<endl;
  36.         return 0;
  37. }
複製代碼

TOP

返回列表