Rearrange a string in sorted order followed by the integer sum | C # program for above implementation ; Method to return string in lexicographic order followed by integers sum ; Traverse the string ; Count occurrence of uppercase alphabets ; Store sum of integers ; Traverse for all characters A to Z ; Append the current character in the string no . of times it occurs in the given string ; Append the sum of integers ; return resultant string ; Driver method
using System ; class GFG { static int MAX_CHAR = 26 ; static String arrangeString ( string str ) { int [ ] char_count = new int [ MAX_CHAR ] ; int sum = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( char . IsUpper ( str [ i ] ) ) char_count [ str [ i ] - ' A ' ] ++ ; else sum = sum + ( str [ i ] - '0' ) ; } string res = " " ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { char ch = ( char ) ( ' A ' + i ) ; while ( char_count [ i ] -- != 0 ) res = res + ch ; } if ( sum > 0 ) res = res + sum ; return res ; } public static void Main ( ) { string str = " ACCBA10D2EW30" ; Console . Write ( arrangeString ( str ) ) ; } }