C#/백준 알고리즘
2022.02.03 [백준] C# 블랙잭
ian's coding
2022. 2. 3. 14:20
728x90
반응형
https://www.acmicpc.net/problem/2798
2798번: 블랙잭
첫째 줄에 카드의 개수 N(3 ≤ N ≤ 100)과 M(10 ≤ M ≤ 300,000)이 주어진다. 둘째 줄에는 카드에 쓰여 있는 수가 주어지며, 이 값은 100,000을 넘지 않는 양의 정수이다. 합이 M을 넘지 않는 카드 3장
www.acmicpc.net
풀이
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
|
using System;
using System.Text;
class Program
{
static void Main()
{
string[] s = Console.ReadLine().Split();
int count = int.Parse(s[0]);
int maxValue = int.Parse(s[1]);
string[] ss = Console.ReadLine().Split();
int[] num = new int[count];
for(int i = 0; i < count; i++)
{
num[i] = int.Parse(ss[i]);
}
int max = 0;
int sum = 0;
for(int i = 0; i < count-2; i++)
{
for(int j = i + 1; j < count - 1; j++)
{
for(int k = j + 1; k < count; k++)
{
sum = num[i] + num[j] + num[k];
if (sum <= maxValue && sum > max)
{
max = sum;
}
}
}
}
Console.WriteLine(max);
}
}
|
cs |
728x90
반응형