How to compare the sizes of playing cards in two chapters with the minimum space

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.