728x90
반응형
https://www.acmicpc.net/problem/1427
1427번: 소트인사이드
첫째 줄에 정렬하려고 하는 수 N이 주어진다. N은 1,000,000,000보다 작거나 같은 자연수이다.
www.acmicpc.net
풀이
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.Text;
using System.IO;
using System.Linq;
using System.Collections.Generic;
class Program
{
static void Main()
{
StreamReader sr = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
StreamWriter sw = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));
string n = sr.ReadLine();
int length = n.Length;
int num = int.Parse(n);
int[] number = new int[length];
for(int i = 0; i < length; i++)
{
//첫번째 자리수 부터 배열에 저장
number[i] = num % 10;
num /= 10;
}
Array.Sort(number);
Array.Reverse(number);
foreach(int i in number)
{
sw.Write(i);
}
sr.Close();
sw.Close();
}
}
|
cs |
728x90
반응형
'C# > 백준 알고리즘' 카테고리의 다른 글
2022.02.05 [백준] C# 좌표 정렬하기 2 (0) | 2022.02.05 |
---|---|
2022.02.05 [백준] C# 좌표 정렬하기 (0) | 2022.02.05 |
2022.02.04 [백준] C# 통계학 (0) | 2022.02.04 |
2022.02.04 [백준] C# 수 정렬하기 3 (0) | 2022.02.04 |
2022.02.04 [백준] C# 수 정렬하기 2 (0) | 2022.02.04 |
댓글