-
-
Save claudianus/6e014eb0156f2d65d51533bc34748976 to your computer and use it in GitHub Desktop.
vb.net 단어 갯수 새기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Module Module1 | |
Sub Main() | |
Const source = "테스트1,테스트1,테스트2,테스트1,테스트3,테스트2,테스트3,테스트1,테스트2,테스트3,테스트4" | |
'단어 파싱 | |
dim arr = Split(source, ",") | |
'갯수 저장용 딕셔너리 | |
Dim dic as new Dictionary(Of String, Integer) | |
'갯수새기 | |
For Each item In arr | |
If dic.ContainsKey(item) Then | |
dic(item) += 1 | |
Else | |
dic(item) = 1 | |
End If | |
Next | |
'단어와 갯수 출력 | |
For Each item In dic.OrderBy(Function(x) x.Value) | |
Console.WriteLine($"{item.Key} {item.Value}개") | |
Next | |
'가장 많은 단어 산출 | |
Dim theGreatestKey = dic.OrderByDescending(Function(x) x.Value).FirstOrDefault() | |
'가장 적은 단어 산출 | |
Dim theLeastKey = dic.OrderBy(Function(x) x.Value).FirstOrDefault() | |
'출력 | |
Console.WriteLine() | |
Console.WriteLine($"가장 적은거: {theLeastKey.Key} {theLeastKey.Value}개") | |
Console.WriteLine($"가장 많은거: {theGreatestKey.Key} {theGreatestKey.Value}개") | |
Console.ReadLine() | |
End Sub | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment