프로그래밍/C#
C# 리스트 조회, 리스트 정렬
코딩줌마
2019. 3. 24. 08:53
StreamReader file = new StreamReader("input.txt");
int size = Int32.Parse(file.ReadLine());
List<string> list = new List<string>();
while (!file.EndOfStream)
{
list.Add(file.ReadLine());
}
//list.Sort();
List<string> newlist = new List<string>();
for (int i = 0; i < list.Count; i++)
{
if (!newlist.Contains(list[i]))
{
newlist.Add(list[i]);
}
}
newlist.Sort(delegate(string a, string b)
{
if (a.Length < b.Length) return -1;
else if (a.Length > b.Length) return 1;
else return string.Compare(a, b);
});
foreach (string item in newlist)
{
Console.WriteLine(item);
}
int size = Int32.Parse(file.ReadLine());
List<string> list = new List<string>();
while (!file.EndOfStream)
{
list.Add(file.ReadLine());
}
//list.Sort();
List<string> newlist = new List<string>();
for (int i = 0; i < list.Count; i++)
{
if (!newlist.Contains(list[i]))
{
newlist.Add(list[i]);
}
}
newlist.Sort(delegate(string a, string b)
{
if (a.Length < b.Length) return -1;
else if (a.Length > b.Length) return 1;
else return string.Compare(a, b);
});
foreach (string item in newlist)
{
Console.WriteLine(item);
}
반응형