There are several requirements:
1) compare whether two playing cards are of the same color,
2) Compare the sizes of two playing cards.
Please design a Data Structure to store information about playing cards.
The most intuitive idea is to store information about a playing card with two memory variables. If you have an object-oriented idea, you will think of using class storage information to define some member functions for comparison and other operations.
In fact, you can use only 6 digits to represent a playing card. Two of them represent a suit of 0000 yuan, 0000 yuan, Yuan,. This means four suits. The last four digits can represent thirteen numbers.
The comparison and other operations can be completed after the hexadecimal format is changed.
Const char mask = 0x30; char card1 = 0x2c; char card2 = 0x06; char card3 = 0x38; cout <(card1 & Mask) = mask); cout <(card2 & Mask) = mask); cout <(card3 & Mask) = mask );
You can also increase the mask size and then compare the size of the last four bits.