identifying pairs in vectors

Ok, I have a deck of 52 cards stored in a vector named V of strings as V[?]=2D for 2 of Diamonds and V[?]=14S for ace of spades, etc... They have been shuffled so they are not in the correct order. I have printed the first 5 cards to be considered a "hand". I need to determine whether or not that hand contains a pair, 2pair, 3ofaKind, 4ofaKind, FullHouse, Flush or Straight. To me, this is much more complicated than usual since the elements contain not only the number but ALSO a letter which indicates the suit. any suggestions? THANK YOU!!
How are the cards represented, by a class, a string, ...?
Here is what I have so far, I know its really long...




#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;

void fillvector(int i, vector<string> &V);
void shuffledeck(vector<string> &V);
void printdeck(int i, vector<string> &V);
void printfive(int i, vector<string> &V);
void evaluatehand(int pos, int i, vector<string> &V);

int main(int argc, char *argv[])
{
vector<string> V;
srand ( unsigned ( time (NULL) ) );
int i;
int pos;
fillvector(i, V);
shuffledeck(V);
printdeck(i, V);
printfive(i, V);
evaluatehand(pos, i, V);


system("PAUSE");
return EXIT_SUCCESS;
}

void fillvector(int i, vector<string> &V)
{
//Aces are high (14)
V.insert(V.end(), 1, "2C" );
V.insert(V.end(), 1, "2H" );
V.insert(V.end(), 1, "2S" );
V.insert(V.end(), 1, "2D" );
V.insert(V.end(), 1, "3C" );
V.insert(V.end(), 1, "3H" );
V.insert(V.end(), 1, "3S" );
V.insert(V.end(), 1, "3D" );
V.insert(V.end(), 1, "4C" );
V.insert(V.end(), 1, "4H" );
V.insert(V.end(), 1, "4S" );
V.insert(V.end(), 1, "4D" );
V.insert(V.end(), 1, "5C" );
V.insert(V.end(), 1, "5H" );
V.insert(V.end(), 1, "5S" );
V.insert(V.end(), 1, "5D" );
V.insert(V.end(), 1, "6C" );
V.insert(V.end(), 1, "6H" );
V.insert(V.end(), 1, "6S" );
V.insert(V.end(), 1, "6D" );
V.insert(V.end(), 1, "7C" );
V.insert(V.end(), 1, "7H" );
V.insert(V.end(), 1, "7S" );
V.insert(V.end(), 1, "7D" );
V.insert(V.end(), 1, "8C" );
V.insert(V.end(), 1, "8H" );
V.insert(V.end(), 1, "8S" );
V.insert(V.end(), 1, "8D" );
V.insert(V.end(), 1, "9C" );
V.insert(V.end(), 1, "9H" );
V.insert(V.end(), 1, "9S" );
V.insert(V.end(), 1, "9D" );
V.insert(V.end(), 1, "10C" );
V.insert(V.end(), 1, "10H" );
V.insert(V.end(), 1, "10S" );
V.insert(V.end(), 1, "10D" );
V.insert(V.end(), 1, "11C" );
V.insert(V.end(), 1, "11H" );
V.insert(V.end(), 1, "11S" );
V.insert(V.end(), 1, "11D" );
V.insert(V.end(), 1, "12C" );
V.insert(V.end(), 1, "12H" );
V.insert(V.end(), 1, "12S" );
V.insert(V.end(), 1, "12D" );
V.insert(V.end(), 1, "13C" );
V.insert(V.end(), 1, "13H" );
V.insert(V.end(), 1, "13S" );
V.insert(V.end(), 1, "13D" );
V.insert(V.end(), 1, "14C" );
V.insert(V.end(), 1, "14H" );
V.insert(V.end(), 1, "14S" );
V.insert(V.end(), 1, "14D" );


}

void shuffledeck(vector<string> &V)
{
random_shuffle( V.begin(), V.end() );

}

void printdeck(int i, vector<string> &V)
{
for(i=0; i < 3 ; ++i)
{
cout << setw(4)<< V[i] << " ";

}
cout << endl;
for(i=3; i < 6 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=6; i < 9 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=9; i < 12 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=12; i < 15 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=15; i < 18 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=18; i < 21 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=21; i < 24 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=24; i < 27 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=27; i < 30 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=30; i < 33 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=33; i < 36 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=36; i < 39 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=39; i < 42 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=42; i < 45 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=45; i < 48 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=48; i < 51 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
for(i=51; i < 52 ; ++i)
{
cout << setw(4)<<V[i] << " ";

}
cout << endl;
}

void printfive(int i, vector<string> &V)
{
cout << "The hand you have been dealt is: ";
for(i= 0 ; i < 5; i++ )
{
cout << V[i] << " ";
}
cout << endl;
}

void evaluatehand(int pos, int i, vector<string> &V)
{

}
Please use [code][/code] tags.
Here is a trick on how to get the value and suit of your cards:
1
2
3
4
5
6
// you need to #include <sstream>
string card = "11S";
stringstream ss ( card ); // create a stream with the contents of the card
int value; 
char suit;
ss >> value >> suit; // read the stream into the variables 
After doing that you can pass the results to some functions for comparison.

BTW V.push_back ( "14D" ); does the same as V.insert(V.end(), 1, "14D" ); with less typing
Personally I would create a Card struct that has two elements which separate out the face value from the suit, since in all of your programming except display to the user you will want to separate them.
ok, so I can use multidimensional vectors for this right? Would it work if I made the rows the numbers and the column the suit? I have never used multidimensional anything before but if that's how I need to do it... So I declared my vector as such:

vector< vector<string> > V;

will this method work? So how would I assign the suits and numbers to this 2D vector? If I say:

V[0][0]= {{"2"}, {"S"}}

will it assign the number 2 to the row and S to the column? And then when I say:

cout << V[0][0] << endl;

will it print "2S" ?
jsmith suggested you a struct
eg:
1
2
3
4
5
struct Card
{
     char suit;
     int value;
};
This would be the easiest thing
And then

vector< Card > deck;
Topic archived. No new replies allowed.