[백준] C# : 2908번 (상수)

Jag·2023년 8월 9일
0

Baekjoon

목록 보기
11/12
post-thumbnail
using System;

namespace BaekjoonTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            string a = s[0];
            string b = s[1];

            char[] aReverse = new char[a.Length];
            int al = a.Length-1;

            char[] bReverse = new char[b.Length];
            int bl = b.Length - 1;

            for(int i = 0; i < a.Length; i++)
            {
                aReverse[al--] = a[i];
                bReverse[bl--] = b[i];
            }

            string aValue = new string(aReverse);
            string bValue = new string(bReverse);
            
            if(int.Parse(aValue)> int.Parse(bValue))
            {
                Console.WriteLine(aValue);
            }
            else
            {
                Console.WriteLine(bValue);
            }
        }
    }
}

처음엔 이렇게 풀이 했음

입력 :734 125

string[]s = Console.ReadLine().Split(); 하게되면
s[0][s[0].length]에는 734(길이 : 3)
s[1][s[1].length]에는 125(길이 : 3)이 들어감

profile
C# Unity Engineer

0개의 댓글