1 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include<iostream>
#include<string>
#include<cstdlib>
#include<ctime>
#include<fstream>
using namespace std;
int main()
{
ifstream in;
ofstream out;
srand(time(0));
out.open("deck.txt");
out << "";
out.close();
string type[4] = { "leaf", "heart", "diamond", "spades" };
string cards[13] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
int record = 0;
int x, y;
string a, b;
while (record < 52)
{
int z = 0;
x = rand() % 4;
y = rand() % 13;
out.open("current.txt");
out << cards[y] << " of " << type[x];
out.close();
in.open("current.txt");
getline(in, a);
in.close();
in.open("deck.txt");
for (int i = 0; i < 52; i++)
{
getline(in, b);
if (a == b)
{
z = 1;
}
else
{
if (z != 1)
{
z = 0;
}
}
}
in.close();
out.open("deck.txt", ios::app);
if (z == 0)
{
out << a << endl;
record = record + 1;
}
out.close();
}
cout << "Enter the number of decks you want to shuffle";
int number;
cin >> number;
string list[52];
in.open("deck.txt");
for (int i = 0; i < 52; i++)
{
getline(in, list[i]);
}
in.close();
out.open("stack.txt");
out << "";
out.close();
int d,e;
int f = 52;
record = 0;
while (record < 52 * number)
{
d = 0;
record = record + 1;
e = rand() % f;
out.open("stack.txt", ios::app);
out << list[e] << endl;
out.close();
cout << record << "\t" << list[e] << endl;
in.open("stack.txt");
for (int i = 0; i < record; i++)
{
getline(in, a);
if (list[e] == a)
{
d = d + 1;
}
}
in.close();
if (d == number)
{
list[e] == "";
out.open("deck.txt");
for (int i = 0; i < f; i++)
{
if (i!=e)
{
out << list[i] << endl;
}
}
out.close();
f = f - 1;
in.open("deck.txt");
for (int i = 0; i < f;i++)
{
getline(in, list[i]);
}
in.close();
}
}
system("pause");
}
|