洗牌 有道2017测试开发工程师编程题

 1 #include <iostream>
 2 #include <vector>
 3 #include <algorithm>
 4 #include <deque>
 5 using namespace std;
 6 
 7 void play(vector<int>& card)
 8 {
 9     const size_t N = card.size();
10     vector<int> cardO = card;
11     int idx = 0;
12     for (int i = 0; i < N / 2; i++)
13     {
14         card[idx++] = cardO[i];
15         card[idx++] = cardO[i + N / 2];
16     }
17 }
18 
19 int main()
20 {
21     int nTest;
22     cin >> nTest;
23     while (nTest--)
24     {
25         int n, k;
26         cin >> n >> k;
27         vector<int> card(2 * n);
28         for (int i = 0; i < 2 * n; i++)
29             cin >> card[i];
30         for (int i = 0; i < k; i++)
31             play(card);
32         for (int i = 0; i < card.size() - 1; i++)
33             cout << card[i] << " ";
34         cout << card[2 * n - 1];
35         cout << endl;
36     }
37 } 
posted @ 2016-08-18 11:30  Pearl_zju  阅读(366)  评论(0编辑  收藏  举报