https://www.acmicpc.net/problem/1181
정렬 문제로 분류된 1181 단어 정렬 문제 입니다.
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _1181
{
class Program
{
public class MyComparer : IComparer<string>
{
public int Compare(string s1, string s2)
{
return s1.CompareTo(s2);
}
}
static void Main(string[] args)
{
int count = int.Parse(Console.ReadLine());
var stringList = new List<string>();
for (int i = 0; i < count; i++)
stringList.Add(Console.ReadLine());
stringList.Sort(new MyComparer());
{
if (stringList[i] == stringList[i + 1])
{
stringList.RemoveAt(i);
i--;
}
}
foreach (string str in stringList)
Console.WriteLine(str);
}
}
}
|
string을 입력받고 IComparer 인터페이스 상속 후 Compare메서드 구현했습니다.
소팅의 방법은
https://programming-mr.tistory.com/46
여기 있습니다.
소트후 똑같은 문자를 삭제하고 출력했습니다.
백준#10814 - 나이순 정렬 (0) | 2020.04.20 |
---|---|
백준#11650 - 좌표 정렬하기 (0) | 2020.04.20 |
백준#1026 - 보물 (0) | 2020.04.20 |
백준#1427 - 소트인사이드 (0) | 2020.04.19 |
백준#1543 - 문서 검색 (0) | 2020.04.18 |