반응형
SMALL
https://www.acmicpc.net/problem/2864
문제
풀이
using System;
using System.IO;
namespace BOJ_2864
{
internal class Program
{
static int sum1;
static int sum2;
static void Main(string[] args)
{
StreamReader sr = new StreamReader(Console.OpenStandardInput());
StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
string[] AB = sr.ReadLine().Split();
string A = AB[0];
string B = AB[1];
char[] tempChar1 = A.ToCharArray();
char[] tempChar2 = B.ToCharArray();
if (B.Contains("5") || A.Contains("5"))
{
for (int j = 0; j < A.Length; j++)
{
if (A[j] == '5')
{
tempChar1[j] = '6';
}
else
tempChar1[j] = A[j];
}
for (int h = 0; h < B.Length; h++)
{
if (B[h] == '5')
{
tempChar2[h] = '6';
}
else
tempChar2[h] = B[h];
}
}
int allSix1 = Convert.ToInt32(new string(tempChar1));
int allSix2 = Convert.ToInt32(new string(tempChar2));
sum1 = allSix1 + allSix2;
for (int j = 0; j < A.Length; j++)
{
if (tempChar1[j] == '6')
{
tempChar1[j] = '5';
}
else
tempChar1[j] = tempChar1[j];
}
for (int j = 0; j < B.Length; j++)
{
if (tempChar2[j] == '6')
{
tempChar2[j] = '5';
}
else
tempChar2[j] = tempChar2[j];
}
int allFive1 = Convert.ToInt32(new string(tempChar1));
int allFive2 = Convert.ToInt32(new string(tempChar2));
sum2 = allFive1 + allFive2;
Console.WriteLine("{0} {1}", sum2,sum1 );
sr.Close();
sw.Close();
}
}
}
각각 입력받은 숫자에 5 혹은 6이 있을시에 5는 전부 6으로 만든뒤 해당 케이스의 합을 구하고 반대로 방금 변경한 숫자를 전부 5로 만들어준뒤 합을구하면 각각 값이 max min 이 된다.
반응형
LIST
'Algorithm > BOJ' 카테고리의 다른 글
[BOJ] 4796번 캠핑 C#사용 알고리즘 풀이 (0) | 2023.02.04 |
---|---|
[BOJ] 1343번 폴리오미노 - C# 사용 - 미해결 (0) | 2023.02.04 |
[BOJ] 10162번 전자레인지 C# 사용 풀이 (0) | 2023.02.01 |
[BOJ] 1789번 수들의 합 C# 사용 풀이 (0) | 2023.01.31 |
[BOJ] 체스판 다시 칠하기 (미해결) - 해결 (0) | 2023.01.31 |