Algorithm

[BOJ/C#] 2864 5와 6의 차이

일등하이 2023. 1. 31. 13:55
반응형

https://www.acmicpc.net/problem/2864

 

2864번: 5와 6의 차이

첫째 줄에 두 정수 A와 B가 주어진다. (1 <= A,B <= 1,000,000)

www.acmicpc.net

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;

namespace BOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
            StreamWriter sw = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));

            string[] ab = sr.ReadLine().Split();
            char[] a = ab[0].ToCharArray();
            char[] b = ab[1].ToCharArray();
            int max = 0;
            int min = 0;
            
            for (int i = 0; i < a.Length; i++)
                if (a[i] == '5') a[i] = '6';
            
            for (int i = 0; i < b.Length; i++)
                if (b[i] == '5') b[i] = '6';

            max = int.Parse(new string(a)) + int.Parse(new string(b));
            
            for (int i = 0; i < a.Length; i++)
                if (a[i] == '6') a[i] = '5';
            
            for (int i = 0; i < b.Length; i++)
                if (b[i] == '6') b[i] = '5';
            
            min = int.Parse(new string(a)) + int.Parse(new string(b));
            
            sw.Write("{0} {1}", min, max);

            sr.Close();
            sw.Close();


        }
        
        
    }
}
반응형