백준 2908 상수
Console Programming/C# Console 2020. 4. 2. 17:08입력받은 숫자를 거꾸로 돌려야한다는 개념은 알고있었으나 Reverse의 적용 후 Array로 바꾼 뒤 다시 string으로 만들어야 하는 부분이 어려웠다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2908
{
class Program
{
static void Main(string[] args)
{
var inputnum = Console.ReadLine().Split();
var str1 = new string(inputnum[0].ToCharArray().Reverse().ToArray());
var str2 = new string(inputnum[1].ToCharArray().Reverse().ToArray());
if (int.Parse(str1) > int.Parse(str2))
{
Console.WriteLine(str1);
}
else
{
Console.WriteLine(str2);
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
인터넷에서 다른 코드를 참조했고, 그 이후 ToCharArray를 쓰지 않아도 된다는 사실을 알았다. string은 이미 char로 이루어진 array이기 때문에
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2908
{
class Program
{
static void Main(string[] args)
{
var inputnum = Console.ReadLine().Split();
var str1 = new string(inputnum[0].Reverse().ToArray());
var str2 = new string(inputnum[1].Reverse().ToArray());
if (int.Parse(str1) > int.Parse(str2))
{
Console.WriteLine(str1);
}
else
{
Console.WriteLine(str2);
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'Console Programming > C# Console' 카테고리의 다른 글
백준 2941 크로아티아 알파벳 (0) | 2020.04.02 |
---|---|
백준 1152 단어의 개수 (0) | 2020.04.02 |
백준 10872 팩토리얼 (0) | 2019.12.20 |
4948 베르트랑 공준 (0) | 2019.12.04 |
1929 소수 구하기 에라토스테네스의 체 (0) | 2019.12.04 |