C#, List를 사용하여 문자열 정력하기이다. 중복테이타는 제외한다.
using System;
using System.Linq; // Distinct()
using System.Collections.Generic;
class progeam
{
private static void Main( ) {
string line;
List<string> list;
list = new List<string>();
while ( (line = Console.ReadLine()) != null ){
list.Add(line);
}
list = list.Distinct().ToList();
list.Sort();
foreach( string str in list ){
Console.WriteLine( str );
}
}
}
/*
Array
LinkedList<T>
List<T>
Stack<T>
Queue<T>
Dictionary<K,T>
SortedDictionary<K,T>
HashSet<T>
SortedSet<T>
*/
각 행에 번호를 추가하려면 다음과 같이 프로그램을 구성하면 된다.
using System;
using System.Linq; // Distinct()
using System.Collections.Generic;
class progeam
{
private static void Main( ) {
string line;
List<string> list;
list = new List<string>();
while ( (line = Console.ReadLine()) != null ){
list.Add(line);
}
list = list.Distinct().ToList();
list.Sort();
int cnt = 0;
foreach( string str in list ){
Console.WriteLine( ++cnt + ") " + str );
}
}
}
'C# 언어' 카테고리의 다른 글
| C#으로 메모리 매칭 게임 만들기 (0) | 2021.09.16 |
|---|---|
| C#으로 스도쿠 만들기 (0) | 2021.09.16 |
| C# 에서 3자리 숫자 입력 받기 (0) | 2021.08.20 |
| C#으로 만든 숫자 야구 게임 (0) | 2021.08.12 |
| 클립보드 내용을 파일로 만들기 (0) | 2021.06.27 |
댓글