201712-2 游戲
- C++
- 總結
本題鏈接:201712-2 游戲
本博客給出本題截圖:

C++
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
int n, k;
cin >> n >> k;
queue<int> q;
for (int i = 1; i <= n; i ++ ) q.push(i);
int j = 1;
while (q.size() > 1)
{
int t = q.front();
q.pop();
if (j % k && j % 10 != k) q.push(t);
j ++ ;
}
cout << q.front() << endl;
return 0;
}
總結
使用佇列可以簡化我們的代碼量,佇列可以直接使用STL中的佇列,也可以用陣列模擬佇列
STL—queue
陣列模擬佇列
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/300554.html
標籤:其他
