Print all 3 digit repeating numbers in a very large number | C # program to print 3 digit repeating numbers ; function to print 3 digit repeating numbers ; Hashmap to store the frequency of a 3 digit number ; first three digit number ; if key already exists increase value by 1 ; Output the three digit numbers with frequency > 1 ; Driver Code ; Input string ; Calling Function
using System ; using System . Collections . Generic ; class GFG { static void printNum ( String s ) { int i = 0 , val = 0 ; Dictionary < int , int > hm = new Dictionary < int , int > ( ) ; val = ( s [ 0 ] - '0' ) * 100 + ( s [ 1 ] - '0' ) * 10 + ( s [ 2 ] - '0' ) ; hm . Add ( val , 1 ) ; for ( i = 3 ; i < s . Length ; i ++ ) { val = ( val % 100 ) * 10 + s [ i ] - '0' ; if ( hm . ContainsKey ( val ) ) { hm [ val ] = hm [ val ] + 1 ; } else { hm . Add ( val , 1 ) ; } } foreach ( KeyValuePair < int , int > en in hm ) { int key = en . Key ; int value = en . Value ; if ( value > 1 ) Console . WriteLine ( key + " ▁ - ▁ " + value + " ▁ times " ) ; } } public static void Main ( String [ ] args ) { String input = "123412345123456" ; printNum ( input ) ; } }