Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to to check if all the characters of a string are with same frequencies in VB.NET

1 Answer

0 votes
Imports System
                 
Public Module Module1
    Public Function same_frequencies(s As String) As Boolean
		Dim letters(256) As Integer
		Dim len As Integer = s.Length
           
        For i As Integer = 0 To len - 1
			if (Char.IsLetter(s(i))) Then
                letters(Convert.ToByte(s(i))) = letters(Convert.ToByte(s(i))) + 1
            End If 
       	Next
	
		Dim frequencies As Integer = 0
        For i As Integer = 0 To 256
			if (letters(i) <> 0) Then
                frequencies = letters(i)
				Exit For
			End If
		Next

		For i As Integer = 0 To 256
			If (letters(i) <> 0 And (letters(i) <> frequencies)) Then
               return false
			End If
		Next
        return true
    End Function
 
    Public Sub Main()
        Dim s As String = "aaabbbcccwww"
          
        If same_frequencies(s) Then
            Console.Write("Yes")
        Else
            Console.Write("No")
        End If
    End Sub
End Module
 


' run
'
' Yes
'

 



answered Jan 2, 2020 by avibootz
...