Created
August 3, 2020 19:05
-
-
Save nguyyentantai/751d29ea8c81d715826d0524c0a3577a to your computer and use it in GitHub Desktop.
random shuffle 52 cards for 4 player c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example program | |
#include <iostream> | |
#include <vector> | |
#include <string> | |
#include <ctime> | |
using namespace std; | |
void printElements(vector<int> v){ | |
for(auto it = v.begin(); it != v.end(); it++){ | |
cout << *it << "\t"; | |
} | |
} | |
void shuffle(vector<int> player[]){ | |
int cards[52]; | |
for(int i = 0; i < 52; i++){ | |
cards[i] = i+1; | |
} | |
for (int i = 52; i >= 1;){ | |
srand(time(NULL)); | |
int j = rand()%i; | |
i--; | |
int temp = cards[i]; | |
cards[i] = cards[j]; | |
cards[j] = temp; | |
} | |
for(int i = 0; i < 52; i++){ | |
cout << cards[i] << " "; | |
} | |
cout << endl; | |
for(int i = 0; i < 4; i++){ | |
for(int j = 0; j < 13; j++){ | |
player[i].push_back(cards[j+i*13]); | |
} | |
} | |
} | |
int main() | |
{ | |
vector<int> player[4]; | |
shuffle(player); | |
for(int i = 0; i < 4; i++){ | |
printElements(player[i]); | |
cout << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment