[BOJ] C# 2309 일곱 난쟁이
Algorithm 2023. 1. 13. 01:16반응형
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _4458
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 20, 7, 23, 19, 10, 15, 25, 8, 13 };
for (int i = 0; i < 8; i++)
{
for (int j = i + 1; j < 9; j++)
{
Console.WriteLine("{0}\t{1}", arr[i], arr[j]);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _4458
{
class Program
{
static void Main(string[] args)
{
int n = 9, sum = 0;
int[] arr = new int[n];
for (int i = 0; i < n; i++)
{
string input = Console.ReadLine();
arr[i] = int.Parse(input);
sum += arr[i];
}
arr = FindDwarfs(arr, n, sum);
Array.Sort(arr);
using (var sw = new StreamWriter(Console.OpenStandardOutput()))
{
for (int i = 0; i < 7; i++)
sw.WriteLine(arr[i]);
}
}
static int[] FindDwarfs(int[] arr, int n, int sum)
{
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (sum - (arr[i] + arr[j]) == 100) //괄호 주의
{
arr[i] = int.MaxValue;
arr[j] = int.MaxValue;
return arr;
}
}
}
return arr;
}
}
}
반응형
'Algorithm' 카테고리의 다른 글
[BOJ] 10974 모든 순열 (0) | 2023.01.13 |
---|---|
[BOJ] 1120 문자열 (0) | 2023.01.13 |
[BOJ] C# 10173 니모를 찾아서 (0) | 2023.01.12 |
[BOJ] 1181 단어정렬 (0) | 2023.01.12 |
[BOJ] 9012 괄호 (0) | 2023.01.11 |