카테고리 없음

[백준] 2621번: 카드게임 [C#]

NaZZU 2024. 5. 5. 02:18

https://www.acmicpc.net/board/view/64912

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
using System.IO;
using System.Text;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Security.Cryptography;
 
namespace 연습장
{
    internal class Program
    {
        static StringBuilder sb = new StringBuilder();
        static void Main(string[] args)
        {
            using var reader = new StreamReader(Console.OpenStandardInput());
            using var print = new StreamWriter(Console.OpenStandardOutput());
 
            _2621_boj boj = new _2621_boj();
 
            boj.boj_2621();
 
        }
    }
    internal class _2621_boj
    {
        public void boj_2621()
        {
            int[] color = new int[4];
            int[] num = new int[10];
            int max = 0;
            int[] pair = new int[2];
            int Triple = 0;
            int Four = 0;
            bool flush = false;
            bool straight = false;
 
            for (int i =0; i < 5; i++)
            {
                string[] input = Console.ReadLine().Split();
                switch (input[0])
                {
                    case "R":
                        color[0]++;
                        break;
                    case "B":
                        color[1]++;
                        break;
                    case "Y":
                        color[2]++;
                        break;
                    default:
                        color[3]++;
                        break;
                }
                num[int.Parse(input[1])]++;
                max = Math.Max(max, int.Parse(input[1]));
            }
            int a = 0;
            for (int i = 1; i<= 9; i++)
            {
                
                if (num[i] == 2)
                    pair[a++= i;
                if (num[i] == 3)
                    Triple = i;
                if (num[i] == 4)
                    Four = i;
            }
 
            if (color[0== 5 || color[1== 5 || color[2== 5 || color[3== 5)
                flush = true;
            for (int i = 0; i < 6; i++)
                if ((num[i] != 0&& (num[i + 1!= 0&& (num[i + 2!= 0&& (num[i + 3!= 0&& (num[i + 4!= 0))
                    straight = true;
 
            if (flush && straight)
                Console.WriteLine(max + 900);
            else if (Four != 0)
                Console.WriteLine(Four + 800);
            else if (Triple != 0 && pair[0!= 0)
                Console.WriteLine(Triple * 10 + (pair[0+ 700));
            else if (flush)
                Console.WriteLine(max + 600);
            else if (straight)
                Console.WriteLine(max + 500);
            else if (Triple != 0)
                Console.WriteLine(Triple + 400);
            else if (pair[0!= 0 && pair[1!= 0)
                Console.WriteLine(300 + Math.Max(pair[0], pair[1]) * 10 + Math.Min(pair[0], pair[1]));
            else if (pair[0!= 0)
                Console.WriteLine(pair[0+ 200);
            else
                Console.WriteLine(max + 100);
 
        }
    }
}
 
cs

단순한 문제였지만 뭐 대단한 문제인거 마냥 메서드를 분할해서 해보려다 코드가 너무 길어져서 다시 하나의 메서드로 통합해서 만들어 주었다.