https://www.acmicpc.net/problem/2870
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2870
{
class Program : IComparer<string>
{
static void Main(string[] args)
{
int count = int.Parse(Console.ReadLine());
var lineList = new List<string>();
for (int i = 0; i < count; i++)
lineList.Add(Console.ReadLine());
var ansList = new List<string>();
foreach (var line in lineList)
{
string strBuff = "";
int buff = 0;
for (int i = 0; i < line.Length; i++)
{
if (int.TryParse(line.Substring(i, 1), out buff))
strBuff += line.Substring(i, 1);
else
{
if (!string.IsNullOrEmpty(strBuff))
ansList.Add(strBuff);
strBuff = "";
}
}
if (!string.IsNullOrEmpty(strBuff))
ansList.Add(strBuff);
}
for (int i = 0; i < ansList.Count; i++)
ansList[i] = Program.DeleteZero(ansList[i]);
ansList.Sort(new Program());
ansList.ForEach(x => Console.WriteLine(x));
}
public int Compare(string s1, string s2)
{
if (s1.Length == s2.Length)
{
for(int i = 0; i < s1.Length; i++)
{
if (s1[i] != s2[i])
return s1[i].CompareTo(s2[i]);
}
return 0;
}
else
return s1.Length.CompareTo(s2.Length);
}
public static string DeleteZero(string s)
{
if(s.Length > 1 && s.First() == '0')
{
return DeleteZero(s.Substring(1));
}
return s;
}
}
}
|
cs |
발견되는 숫자가 int, long을 넘어가는 경우가 있어 string으로 처리하여 정리했습니다.
자릿수가 같다면 자리를 하나씩 보며 비교했고 자릿수가 다르다면 큰것을 뒤로 보내면 됩니다.
앞에 불필요하게 나오는 0이 발생하는데 이걸 없애기 위해 DeleteZero함수를 정의했습니다.
가장 앞의 0을 지우고 재귀호출 했습니다.
백준 #2504 - 괄호의 값 (0) | 2020.06.13 |
---|---|
백준 #1343 - 폴리오미노 (0) | 2020.05.30 |
백준# 9996 - 한국이 그리울 땐 서버에 접속하지 (0) | 2020.05.16 |
백준# 9933 - 민균이의 비밀번호 (0) | 2020.05.15 |
백준# 7569 - 덩치 (0) | 2020.05.13 |