Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int suit0();
- int num0();
- int draw(int *suit, int *num);
- int main(void) {
- char hs;
- int suit, num, status;
- srand((unsigned) time(NULL));
- do {
- printf("Hit or Stand?(h/s):");
- scanf(" %c", &hs);
- switch (hs) {
- case 'h':
- while(1) {
- suit = suit0();
- num = num0();
- status = draw(&suit, &num);
- if (!status) break;
- if (status == -1) {
- printf("All cards is open.\n");
- return 0;
- }
- }
- if (suit == 1)
- printf("S");
- else if (suit == 2)
- printf("H");
- else if (suit == 3)
- printf("C");
- else
- printf("D");
- if (num == 1)
- printf("A\n");
- else if (num == 11)
- printf("J\n");
- else if (num == 12)
- printf("Q\n");
- else if (num == 13)
- printf("K\n");
- else
- printf("%d\n", num);
- break;
- case 's':
- return 0;
- default:
- printf("hかsを入力してください。\n");
- break;
- }
- } while (hs != 's');
- return 0;
- }
- int suit0(void) {
- return rand() % 4 + 1;
- }
- int num0(void) {
- return rand() % 13 + 1;
- }
- int draw(int *suit0, int *num0) {
- int i, j, all = 0;
- static int sn[4][13] = {
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
- };
- if (!sn[*suit0 - 1][*num0 - 1]++) return 0;
- for (i = 0; i < 4; i++)
- for (j = 0; j < 13; j++)
- if (sn[i][j]) all++;
- if (all == 52) return -1;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement