Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 20161103樸克牌.cpp : 定義主控台應用程式的進入點。
- //
- #include "stdio.h"
- #include<stdlib.h>
- #include<time.h>
- #include<stdbool.h>
- #define NUM_CARD 5
- #define RANK_TYPE 13
- #define FLOWER_TYPE 4
- void release_card(void);
- void check_card(void);
- void show_funtion(void);
- int rank[RANK_TYPE];
- int flower[FLOWER_TYPE];
- int differ_rank = 0, differ_flower = 0;
- bool hand_card[FLOWER_TYPE][RANK_TYPE];
- bool royal_flush = 0, flush = 0, straight = 0, four = 0, three = 0;
- int pairs;
- int main()
- {
- while (1)
- {
- release_card();
- check_card();
- show_funtion();
- }
- return 0;
- }
- void release_card(void)
- {
- int time = 0;
- for (int i = 0; i < RANK_TYPE; i++)
- {
- rank[i] = 0;
- for (int j = 0; j < FLOWER_TYPE; j++)
- hand_card[j][i] = 0;
- }
- for (int i = 0; i < FLOWER_TYPE; i++)flower[i] =0;
- royal_flush = 0, flush = 0, straight = 0, four = 0, three = 0,pairs=0;
- while (time<NUM_CARD)
- {
- char ch, rank_ch, suit_ch;
- bool badcard = 0;
- int tmprank, tmpflower;
- rank_ch = getchar();
- switch (rank_ch)
- {
- case '0': exit(0);
- case '2': tmprank=0; break;
- case '3': tmprank=1; break;
- case '4': tmprank=2; break;
- case '5': tmprank=3; break;
- case '6': tmprank=4; break;
- case '7': tmprank=5; break;
- case '8': tmprank=6; break;
- case '9': tmprank=7; break;
- case 't':case 'T': tmprank=8; break;
- case 'j':case 'J': tmprank=9; break;
- case 'q':case 'Q': tmprank=10; break;
- case 'k':case 'K': tmprank=11; break;
- case 'a':case 'A': tmprank=12; break;
- default: badcard = 1; break;
- }
- suit_ch = getchar();
- switch (suit_ch)
- {
- case 's':case 'S': tmpflower=3; break;
- case 'h':case 'H': tmpflower=2; break;
- case 'd':case 'D': tmpflower=1; break;
- case 'c':case 'C': tmpflower=0; break;
- default: badcard = 1; break;
- }
- while (ch = getchar() != '\n')
- if (ch != ' ')badcard = 1;
- if (badcard)printf("Bad card; ignored.\n");
- else if (hand_card[tmpflower][tmprank])
- {
- printf("Duplicate card; ignored.\n");
- continue;
- }
- else
- {
- hand_card[tmpflower][tmprank] = 1;
- rank[tmprank]++;
- flower[tmpflower]++;
- time++;
- }
- }
- }
- void check_card(void)
- {
- int i,keep=0;
- for (i = 0; i < RANK_TYPE; i++)//flush
- if (flower[i] == NUM_CARD)flush = 1;
- for (i = 0; rank[i] == 0; i++);//straight
- for (i; (i < RANK_TYPE) && (rank[i] == 1); i++, keep++);
- if (keep == 5)straight = 1;
- if (keep == 5 && i == 13 && flush == 1)royal_flush = 1;//royalflush
- for (i = 0; i < RANK_TYPE; i++)
- {
- if (rank[i]!=0)differ_rank++;
- if (rank[i] >= 4)four = 1;
- if (rank[i] == 3)three = 1;
- if (rank[i] == 2)pairs++;
- }
- }
- void show_funtion(void)
- {
- if (royal_flush)puts("royal flush");
- else if (straight&&flush)puts("straight of flush");
- else if (four)puts("four of kind");
- else if (three&&pairs==1)puts("full house");
- else if (straight)puts("straight");
- else if (three)puts("Three of kind");
- else if (pairs == 2)puts("two pair");
- else if (pairs)puts("pair");
- else puts("hight card");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement