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;
- srand((unsigned) time(NULL));
- do {
- printf("Hit or Stand?(h/s):");
- scanf(" %c", &hs);
- switch (hs) {
- case 'h':
- while(1) {
- suit = suit0();
- num = num0();
- if (!draw(suit, num)) break;
- }
- 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) {
- 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][num0] > 0)
- return 1;
- else {
- sn[suit0][num0]++;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement