본문 바로가기
Computer Science

프양연 Poker / 정리 후 if else

by OKOK 2018. 12. 24.

1. 알고리즘을 알고 있어야

2. 어떤 알고리즘을 써서 풀지 계산 완료

3. O(N)이 아닌, 자주 쓰는 알고리즘을 적용 할 수 있는지 확인

4. 오케이. 그리고 문제 풀이하면 끝

5. 간단한 아이디어와 정확히 적용가능한 알고리즘의 범위만 알고 있으면 됨 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include <stdio.h>
 
int card[14][5];
 
void init(void)
{
    int i, j;
 
    for (i = 0; i < 14; i++)
    {
        for (j = 0; j < 5; j++)
        {
            card[i][j] = 0;
        }
    }
}
 
void check_card(char ch, int num)
{
    int m;
 
    if (ch == 'S') m = 1;
    else if (ch == 'D') m = 2;
    else if (ch == 'H') m = 3;
    else m = 4;
 
    card[num][m] = 1;
}
 
int check_straight(int type)
{
    int i, j;
    int sum = 0;
 
    for (i = 1; i <= 9; i++)
    {
        sum = 0;
        for (j = 0; j < 5; j++)
        {
            if (card[i + j][type])
            {
                sum++;
            }
        }
 
        if (sum >= 5)
        {
            return 1;
        }
    }
 
    sum = 0;
    for (j = 10; j < 14; j++)
    {
        if (card[j][type])
            sum++;
    }
    if (card[1][type]) sum++;
 
    if (sum == 5return 1;
 
    return 0;
}
 
void check_result(void)
{
    int i, j;
 
    int is_flush = 0;
    int is_poker = 0;
 
    int count_3 = 0;
    int count_2 = 0;
 
 
    for (i = 1; i < 14; i++)
    {
        card[0][1+= card[i][1];
        card[0][2+= card[i][2];
        card[0][3+= card[i][3];
        card[0][4+= card[i][4];
    }
 
    for (i = 1; i < 14; i++)
    {
        for (j = 1; j <= 4; j++)
        {
            card[i][0+= card[i][j];
        }
    }
 
    for (i = 1; i <= 13; i++)
    {
        if (card[i][0== 4)
        {
            is_poker = 1;
            printf("4 Card");
            return;
        }
    }
 
    if (card[0][1> 4)
        is_flush = 1;
    else if (card[0][2> 4)
        is_flush = 2;
    else if (card[0][3> 4)
        is_flush = 3;
    else if (card[0][4> 4)
        is_flush = 4;
 
    if (is_flush)
    {
        if (check_straight(is_flush))
        {
            printf("Straight Flush");
            return;
        }
        else
        {
            printf("Flush");
            return;
        }
    }
 
    if (check_straight(0))
    {
        printf("Straight");
        return;
    }
 
    for (i = 1; i < 14; i++)
    {
        if (card[i][0== 3) count_3++;
        if (card[i][0== 2) count_2++;
    }
 
    if (count_3 == 2 || (count_3 == 1 && count_2 > 0))
    {
        printf("Full House");
        return;
    }
 
    if (count_3 > 0 && count_2 == 0)
    {
        printf("Triple");
        return;
    }
 
    if (count_2 >= 2 && count_3 == 0)
    {
        printf("2 Pair");
        return;
    }
 
    if (count_2 > 0 && count_3 == 0)
    {
        printf("1 Pair");
        return;
    }
 
    printf("Top");
 
}
 
 
int main(void)
{
    int test_case;
    int T;
 
    int N;
 
    int i, j;
    char ch[2];
    int num;
 
    freopen("input.txt""r", stdin);
    setbuf(stdout, NULL);
    scanf("%d"&T);
 
    for (test_case = 1; test_case <= T; ++test_case)
    {
        init();
 
        for (j = 0; j < 7; j++)
        {
            scanf("%s %d", ch, &num);
            check_card(ch[0], num);
        }
 
        printf("#%d ", test_case);
        check_result();
        printf("\n");
 
    }
    return 0//정상종료시 반드시 0을 리턴해야 합니다.
}
 
cs


댓글