C#/백준 알고리즘
2022.02.05 [백준] C# 단어 정렬
ian's coding
2022. 2. 5. 14:21
728x90
반응형
https://www.acmicpc.net/problem/1181
1181번: 단어 정렬
첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다.
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()));
StringBuilder sb = new StringBuilder();
int n = int.Parse(sr.ReadLine());
List<string> list = new List<string>();
for(int i = 0; i < n; i++)
{
list.Add(sr.ReadLine());
}
list = list.Distinct().ToList();
list.Sort();
list = list.OrderBy(x => x.Length).ToList();
for(int i = 0; i < list.Count; i++)
{
sw.WriteLine(list[i]);
}
sr.Close();
sw.Close();
}
}
|
cs |
728x90
반응형