Algorithm/BOJ

[BOJ] 2864 5와 6의 차이 c# 사용 풀이

Bueong_E 2023. 2. 1. 20:20
반응형
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