PC/UVa:110205/10205
根据dealer的洗牌方法迭代。
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
int n = 0;
cin >> n;
cin.get();
cin.get();
for (int k = 0; k < n; k++)
{
int cnt = 0, suit = 0, num = 0;
unsigned long idx;
cin >> cnt;
vector<vector<int>> viiShuffle(cnt, vector<int>(52, 0));
vector<int> viInput(52, 0), viOutput(52, 0);
for (int i = 0; i < cnt; i++)
{
for (int j = 0; j < 52; j++)
{
cin >> viiShuffle[i][j];
viInput[j] = j;
}
}
cin.get();
string strIdx;
while (getline(cin, strIdx)){
if (strIdx.empty()) break;
idx = stoul(strIdx);
for (int j = 0; j < 52; j++)
{
viOutput[j] = viInput[viiShuffle[idx - 1][j] - 1];
}
viInput.assign(viOutput.begin(), viOutput.end());
}
for (int j = 0; j < 52; j++)
{
suit = viOutput[j] / 13;
num = viOutput[j] % 13;
if (num >= 0 && num <= 8) cout << num + 2;
else if (num == 9) cout << "Jack";
else if (num == 10) cout << "Queen";
else if (num == 11) cout << "King";
else if (num == 12) cout << "Ace";
cout << " of ";
if (suit == 0) cout << "Clubs" << endl;
else if (suit == 1) cout << "Diamonds" << endl;
else if (suit == 2) cout << "Hearts" << endl;
else if (suit == 3) cout << "Spades" << endl;
//cout << viOutput[j] << ' ';
}
if (k != n - 1)cout << endl;
}
return 0;
}
/*
1
2
2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 52 51
52 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 1
1
2
*/
本文介绍了一种基于洗牌算法的卡牌迭代方法,通过使用C++实现,展示了如何根据特定的洗牌规则对一副标准的52张扑克牌进行重新排序。算法首先读取洗牌次数和每次洗牌的顺序,然后根据这些输入迭代更新卡牌位置,最终输出每张牌的名称和花色。
229

被折叠的 条评论
为什么被折叠?



