codeparrot/xlcost-text-to-code huggingface dataset:
Print a number as string of ' A ' and ' B ' in lexicographic order | C # implementation of the approach ; Function to calculate number of characters in corresponding string of ' A ' and ' B ' ; Since the minimum number of characters will be 1 ; Calculating number of characters ; Since k length string can represent at most pow ( 2 , k + 1 ) - 2 that is if k = 4 , it can represent at most pow ( 2 , 4 + 1 ) - 2 = 30 so we have to calculate the length of the corresponding string ; return the length of the corresponding string ; Function to print corresponding string of ' A ' and ' B ' ; Find length of string ; Since the first number that can be represented by k length string will be ( pow ( 2 , k ) - 2 ) + 1 and it will be AAA ... A , k times , therefore , N will store that how much we have to print ; At a particular time , we have to decide whether we have to print ' A ' or ' B ' , this can be check by calculating the value of pow ( 2 , k - 1 ) ; Print new line ; Driver code
using System ; class GFG { static int no_of_characters ( int M ) { int k = 1 ; while ( true ) { if ( ( int ) Math . Pow ( 2 , k + 1 ) - 2 < M ) k ++ ; else break ; } return k ; } static void print_string ( int M ) { int k , num , N ; k = no_of_characters ( M ) ; N = M - ( ( int ) Math . Pow ( 2 , k ) - 2 ) ; while ( k > 0 ) { num = ( int ) Math . Pow ( 2 , k - 1 ) ; if ( num >= N ) Console . Write ( " A " ) ; else { Console . Write ( " B " ) ; N -= num ; } k -- ; } Console . WriteLine ( ) ; } public static void Main ( ) { int M ; M = 30 ; print_string ( M ) ; M = 55 ; print_string ( M ) ; M = 100 ; print_string ( M ) ; } }
Replace two substrings ( of a string ) with each other | C # implementation of the approach ; Function to return the resultant string ; Iterate through all positions i ; Current sub - string of length = len ( A ) = len ( B ) ; If current sub - string gets equal to A or B ; Update S after replacing A ; Update S after replacing B ; Return the updated string ; Driver code
using System ; class GFG { static string updateString ( string S , string A , string B ) { int l = A . Length ; for ( int i = 0 ; i + l <= S . Length ; i ++ ) { string curr = S . Substring ( i , l ) ; if ( curr . Equals ( A ) ) { string new_string = S . Substring ( 0 , i ) + B + S . Substring ( i + l ) ; S = new_string ; i += l - 1 ; } else { string new_string = S . Substring ( 0 , i ) + A + S . Substring ( i + l ) ; S = new_string ; i += l - 1 ; } } return S ; } public static void Main ( ) { string S = " aab " ; string A = " aa " ; string B = " bb " ; Console . WriteLine ( updateString ( S , A , B ) ) ; } }
Print n 0 s and m 1 s such that no two 0 s and no three 1 s are together | C # implementation of the above approach ; Function to print the required pattern ; When condition fails ; When m = n - 1 ; Driver code
using System ; class GFG { static void printPattern ( int n , int m ) { if ( m > 2 * ( n + 1 ) m < n - 1 ) { Console . Write ( " - 1" ) ; } else if ( Math . Abs ( n - m ) <= 1 ) { while ( n > 0 && m > 0 ) { Console . Write ( "01" ) ; n -- ; m -- ; } if ( n != 0 ) { Console . Write ( "0" ) ; } if ( m != 0 ) { Console . Write ( "1" ) ; } } else { while ( m - n > 1 && n > 0 ) { Console . Write ( "110" ) ; m = m - 2 ; n = n - 1 ; } while ( n > 0 ) { Console . Write ( "10" ) ; n -- ; m -- ; } while ( m > 0 ) { Console . Write ( "1" ) ; m -- ; } } } public static void Main ( ) { int n = 4 , m = 8 ; printPattern ( n , m ) ; } }
Find the count of Strictly decreasing Subarrays | C # program to count number of strictly decreasing subarrays in O ( n ) time . ; Function to count the number of strictly decreasing subarrays ; Initialize length of current decreasing subarray ; Traverse through the array ; If arr [ i + 1 ] is less than arr [ i ] , then increment length ; Else Update count and reset length ; If last length is more than 1 ; Driver code
using System ; class GFG { static int countDecreasing ( int [ ] A , int n ) { int len = 1 ; for ( int i = 0 ; i < n - 1 ; ++ i ) { if ( A [ i + 1 ] < A [ i ] ) len ++ ; else { cnt += ( ( ( len - 1 ) * len ) / 2 ) ; len = 1 ; } } if ( len > 1 ) cnt += ( ( ( len - 1 ) * len ) / 2 ) ; return cnt ; } static void Main ( ) { int [ ] A = { 100 , 3 , 1 , 13 } ; int n = A . Length ; Console . WriteLine ( countDecreasing ( A , n ) ) ; } }
Minimum changes required to make first string substring of second string | C # program to find the minimum number of characters to be replaced in string S2 , such that S1 is a substring of S2 ; Function to find the minimum number of characters to be replaced in string S2 , such that S1 is a substring of S2 ; Get the sizes of both strings ; Traverse the string S2 ; From every index in S2 , check the number of mis - matching characters in substring of length of S1 ; Take minimum of prev and current mis - match ; return answer ; Driver Code
using System ; class GFG { static int minimumChar ( String S1 , String S2 ) { int n = S1 . Length ; int m = S2 . Length ; int ans = Int32 . MaxValue ; for ( int i = 0 ; i < m - n + 1 ; i ++ ) { int minRemovedChar = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( S1 [ j ] != S2 [ i + j ] ) { minRemovedChar ++ ; } } ans = Math . Min ( minRemovedChar , ans ) ; } return ans ; } public static void Main ( ) { String S1 = " abc " ; String S2 = " paxzk " ; Console . WriteLine ( minimumChar ( S1 , S2 ) ) ; } }
Frequency of a substring in a string | Simple C # program to count occurrences of pat in txt . ; A loop to slide pat [ ] one by one ; For current index i , check for pattern match ; if pat [ 0. . . M - 1 ] = txt [ i , i + 1 , ... i + M - 1 ] ; Driver program to test above function
using System ; public class GFG { static int countFreq ( String pat , String txt ) { int M = pat . Length ; int N = txt . Length ; int res = 0 ; for ( int i = 0 ; i <= N - M ; i ++ ) { int j ; for ( j = 0 ; j < M ; j ++ ) { if ( txt [ i + j ] != pat [ j ] ) { break ; } } if ( j == M ) { res ++ ; j = 0 ; } } return res ; } static public void Main ( ) { String txt = " dhimanman " ; String pat = " man " ; Console . Write ( countFreq ( pat , txt ) ) ; } }
Optimized Naive Algorithm for Pattern Searching | C # program for A modified Naive Pattern Searching algorithm that is optimized for the cases when all characters of pattern are different ; A modified Naive Pattern Searching algorithm that is optimized for the cases when all characters of pattern are different ; For current index i , check for pattern match ; if ( j == M ) if pat [ 0. . . M - 1 ] = txt [ i , i + 1 , ... i + M - 1 ] ; slide the pattern by j ; Driver code
using System ; class GFG { static void search ( string pat , string txt ) { int M = pat . Length ; int N = txt . Length ; int i = 0 ; while ( i <= N - M ) { int j ; for ( j = 0 ; j < M ; j ++ ) if ( txt [ i + j ] != pat [ j ] ) break ; { Console . WriteLine ( " Pattern ▁ found ▁ at ▁ index ▁ " + i ) ; i = i + M ; } else if ( j = = 0 ) i = i + 1 ; else i = i + j ; } } static void Main ( ) { string txt = " ABCEABCDABCEABCD " ; string pat = " ABCD " ; search ( pat , txt ) ; } }
Find the missing digit in given product of large positive integers | C # program for the above approach ; Function to find the replaced digit in the product of a * b ; Keeps track of the sign of the current digit ; Stores the value of a % 11 ; Find the value of a mod 11 for large value of a as per the derived formula ; Stores the value of b % 11 ; Find the value of b mod 11 for large value of a as per the derived formula ; Stores the value of c % 11 ; Keeps track of the sign of x ; If the current digit is the missing digit , then keep the track of its sign ; Find the value of x using the derived equation ; Check if x has a negative sign ; Return positive equivaluent of x mod 11 ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int findMissingDigit ( string a , string b , string c ) { int w = 1 ; int a_mod_11 = 0 ; for ( int i = a . Length - 1 ; i >= 0 ; i -- ) { a_mod_11 = ( a_mod_11 + w * ( ( int ) a [ i ] - 48 ) ) % 11 ; w = w * - 1 ; } int b_mod_11 = 0 ; w = 1 ; for ( int i = b . Length - 1 ; i >= 0 ; i -- ) { b_mod_11 = ( b_mod_11 + w * ( ( int ) b [ i ] - 48 ) ) % 11 ; w = w * - 1 ; } int c_mod_11 = 0 ; bool xSignIsPositive = true ; w = 1 ; for ( int i = c . Length - 1 ; i >= 0 ; i -- ) { if ( c [ i ] == ' x ' ) { xSignIsPositive = ( w == 1 ) ; } else { c_mod_11 = ( c_mod_11 + w * ( ( int ) c [ i ] - '0' ) ) % 11 ; } w = w * - 1 ; } int x = ( ( a_mod_11 * b_mod_11 ) - c_mod_11 ) % 11 ; if ( xSignIsPositive == false ) { x = - x ; } return ( x % 11 + 11 ) % 11 ; } public static void Main ( ) { string A = "123456789" ; string B = "987654321" ; string C = "12193263111x635269" ; Console . Write ( findMissingDigit ( A , B , C ) ) ; } }
Check if a string can be made empty by repeatedly removing given subsequence | C # program for the above approach ; Function to check if a string can be made empty by removing all subsequences of the form " GFG " or not ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void findIfPossible ( int N , string str ) { int countG = 0 , countF = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' G ' ) countG ++ ; else countF ++ ; } if ( 2 * countF != countG ) { Console . WriteLine ( " NO " ) ; } else { int id = 0 ; bool flag = true ; for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' G ' ) { countG -- ; id ++ ; } else { countF -- ; id -- ; } if ( id < 0 ) { flag = false ; break ; } if ( countG < countF ) { flag = false ; break ; } } if ( flag ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } } public static void Main ( ) { int n = 6 ; string str = " GFGFGG " ; findIfPossible ( n , str ) ; } }
Check whether second string can be formed from characters of first string used any number of times | C # implementation of the above approach ; Function to check if str2 can be made by characters of str1 or not ; To store the occurrence of every character ; Length of the two strings ; Assume that it is possible to compose the string str2 from str1 ; Iterate over str1 ; Store the presence of every character ; Iterate over str2 ; Ignore the spaces ; Check for the presence of character in str1 ; If it is possible to make str2 from str1 ; Driver Code ; Given strings ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void isPossible ( string str1 , string str2 ) { int [ ] arr = new int [ 256 ] ; Array . Clear ( arr , 0 , 256 ) ; int l1 = str1 . Length ; int l2 = str2 . Length ; int i ; bool possible = true ; for ( i = 0 ; i < l1 ; i ++ ) { arr [ str1 [ i ] ] = 1 ; } for ( i = 0 ; i < l2 ; i ++ ) { if ( str2 [ i ] != ' ▁ ' ) { if ( arr [ str2 [ i ] ] == 1 ) continue ; else { possible = false ; break ; } } } if ( possible ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } public static void Main ( ) { string str1 = " we ▁ all ▁ love ▁ geeksforgeeks " ; string str2 = " we ▁ all ▁ love ▁ geeks " ; isPossible ( str1 , str2 ) ; } }
Longest subsequence with consecutive English alphabets | C # program for the above approach ; Function to find the length of subsequence starting with character ch ; Length of the string ; Stores the maximum length ; Traverse the given string ; If s [ i ] is required character ch ; Increment ans by 1 ; Increment character ch ; Return the current maximum length with character ch ; Function to find the maximum length of subsequence of consecutive characters ; Stores the maximum length of consecutive characters ; Update ans ; Return the maximum length of subsequence ; Driver Code ; Input ; Function Call
using System ; using System . Collections . Generic ; class GFG { static int findSubsequence ( string S , char ch ) { int N = S . Length ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ch ) { ans ++ ; ch ++ ; } } return ans ; } static int findMaxSubsequence ( string S ) { int ans = 0 ; for ( char ch = ' a ' ; ch <= ' z ' ; ch ++ ) { ans = Math . Max ( ans , findSubsequence ( S , ch ) ) ; } return ans ; } public static void Main ( ) { string S = " abcabefghijk " ; Console . Write ( findMaxSubsequence ( S ) ) ; } }
Minimum number of alternate subsequences required to be removed to empty a Binary String | C # program for the above approach ; Function to find the minimum number of operations to empty a binary string ; Stores the resultant number of operations ; Stores the number of 0 s ; Stores the number of 1 s ; Traverse the given string ; To balance 0 with 1 if possible ; Increment the value of cn0 by 1 ; To balance 1 with 0 if possible ; Increment the value of cn1 ; Update the maximum number of unused 0 s and 1 s ; Print the resultant count ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void minOpsToEmptyString ( string s ) { int ans = 0 ; int cn0 = 0 ; int cn1 = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] == '0' ) { if ( cn1 > 0 ) cn1 -- ; cn0 ++ ; } else { if ( cn0 > 0 ) cn0 -- ; cn1 ++ ; } ans = Math . Max ( ans , Math . Max ( cn0 , cn1 ) ) ; } Console . Write ( ans ) ; } public static void Main ( ) { string S = "010101" ; minOpsToEmptyString ( S ) ; } }
Smallest string obtained by removing all occurrences of 01 and 11 from Binary String | Set 2 | C # program for the above approach ; Function to find the length of the smallest string possible by removing substrings "01" and "11" ; Stores the length of the smallest string ; Traverse the string S ; If st is greater than 0 and S [ i ] is '1' ; Delete the last character and decrement st by 1 ; Otherwise ; Increment st by 1 ; Return the answer in st ; Driver code ; Input ; Function call
using System ; public class GFG_JAVA { static int shortestString ( string S , int N ) { int st = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( st > 0 && S [ i ] == '1' ) { st -- ; } else { st ++ ; } } return st ; } public static void Main ( string [ ] args ) { string S = "1010" ; int N = S . Length ; Console . WriteLine ( shortestString ( S , N ) ) ; } }
Longest Non | C # program for the above approach ; Function to find the length of the longest non - increasing subsequence ; Stores the prefix and suffix count of 1 s and 0 s respectively ; Initialize the array ; Store the number of '1' s up to current index i in pre ; Find the prefix sum ; If the current element is '1' , update the pre [ i ] ; Store the number of '0' s over the range [ i , N - 1 ] ; Find the suffix sum ; If the current element is '0' , update post [ i ] ; Stores the maximum length ; Find the maximum value of pre [ i ] + post [ i ] ; Return the answer ; Driver Code
using System ; class GFG { static int findLength ( String str , int n ) { int [ ] pre = new int [ n ] ; int [ ] post = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { pre [ i ] = 0 ; post [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { if ( i != 0 ) { pre [ i ] += pre [ i - 1 ] ; } if ( str [ i ] == '1' ) { pre [ i ] += 1 ; } } for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( i != n - 1 ) post [ i ] += post [ i + 1 ] ; if ( str [ i ] == '0' ) post [ i ] += 1 ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans = Math . Max ( ans , pre [ i ] + post [ i ] ) ; } return ans ; } public static void Main ( String [ ] args ) { String S = "0101110110100001011" ; Console . WriteLine ( findLength ( S , S . Length ) ) ; } }
Number of substrings having an equal number of lowercase and uppercase letters | C # program for the above approach ; Function to find the count of substrings having an equal number of uppercase and lowercase characters ; Stores the count of prefixes having sum S considering uppercase and lowercase characters as 1 and - 1 ; Stores the count of substrings having equal number of lowercase and uppercase characters ; Stores the sum obtained so far ; If the character is uppercase ; Otherwise ; If currsum is 0 ; If the current sum exists in the Dictionary prevSum ; Increment the resultant count by 1 ; Update the frequency of the current sum by 1 ; Return the resultant count of the subarrays ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int countSubstring ( String S , int N ) { Dictionary < int , int > prevSum = new Dictionary < int , int > ( ) ; int res = 0 ; int currentSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] >= ' A ' && S [ i ] <= ' Z ' ) { currentSum ++ ; } else currentSum -- ; if ( currentSum == 0 ) res ++ ; if ( prevSum . ContainsKey ( currentSum ) ) { res += prevSum [ currentSum ] ; prevSum [ currentSum ] = prevSum [ currentSum ] + 1 ; } else prevSum . Add ( currentSum , 1 ) ; } return res ; } public static void Main ( String [ ] args ) { String S = " gEEk " ; Console . WriteLine ( countSubstring ( S , S . Length ) ) ; } }
Number of substrings with each character occurring even times | C # program for the above approach ; Function to count substrings having even frequency of each character ; Stores the total count of substrings ; Traverse the range [ 0 , N ] : ; Traverse the range [ i + 1 , N ] ; Stores the substring over the range of indices [ i , len ] ; Stores the frequency of characters ; Count frequency of each character ; Traverse the dictionary ; If any of the keys have odd count ; Otherwise ; Return count ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { static int subString ( string s , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int len = i + 1 ; len <= n ; len ++ ) { string test_str = s . Substring ( i , len - i ) ; Dictionary < char , int > res = new Dictionary < char , int > ( ) ; foreach ( char keys in test_str . ToCharArray ( ) ) { if ( ! res . ContainsKey ( keys ) ) res . Add ( keys , 0 ) ; res [ keys ] ++ ; } int flag = 0 ; foreach ( KeyValuePair < char , int > keys in res ) { if ( keys . Value % 2 != 0 ) { flag = 1 ; break ; } } if ( flag == 0 ) count += 1 ; } } return count ; } static public void Main ( ) { string S = " abbaa " ; int N = S . Length ; Console . WriteLine ( subString ( S , N ) ) ; } }
Count new pairs of strings that can be obtained by swapping first characters of pairs of strings from given array | C # program for the above approach ; Function to count new pairs of strings that can be obtained by swapping first characters of any pair of strings ; Stores the count of pairs ; Generate all possible pairs of strings from the array arr [ ] ; Stores the current pair of strings ; Swap the first characters ; Check if they are already present in the array or not ; If both the strings are not present ; Increment the ans by 1 ; Print the resultant count ; Driver Code
using System ; class GFG { static void countStringPairs ( string [ ] a , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { char [ ] p = a [ i ] . ToCharArray ( ) ; char [ ] q = a [ j ] . ToCharArray ( ) ; if ( p [ 0 ] != q [ 0 ] ) { char temp = p [ 0 ] ; p [ 0 ] = q [ 0 ] ; q [ 0 ] = temp ; int flag1 = 0 ; int flag2 = 0 ; for ( int k = 0 ; k < n ; k ++ ) { if ( a [ k ] . Equals ( new string ( p ) ) ) { flag1 = 1 ; } if ( a [ k ] . Equals ( new string ( q ) ) ) { flag2 = 1 ; } } if ( flag1 == 0 && flag2 == 0 ) { ans = ans + 1 ; } } } } Console . WriteLine ( ans ) ; } public static void Main ( string [ ] args ) { string [ ] arr = { " good " , " bad " , " food " } ; int N = arr . Length ; countStringPairs ( arr , N ) ; } }
Modify string by replacing characters by alphabets whose distance from that character is equal to its frequency | C # program for the above approach ; Function to modify string by replacing characters by the alphabet present at distance equal to frequency of the string ; Stores frequency of characters ; Stores length of the string ; Traverse the given string S ; Increment frequency of current character by 1 ; Traverse the string ; Store the value to be added to the current character ; Check if after adding the frequency , the character is less than ' z ' or not ; Otherwise , update the value of add so that s [ i ] doesn ' t ▁ exceed ▁ ' z ' ; Print the modified string ; Driver Code
using System ; class GFG { static void addFrequencyToCharacter ( char [ ] s ) { int [ ] frequency = new int [ 26 ] ; int n = s . Length ; for ( int i = 0 ; i < n ; i ++ ) { frequency [ s [ i ] - ' a ' ] += 1 ; } for ( int i = 0 ; i < n ; i ++ ) { int add = frequency [ s [ i ] - ' a ' ] % 26 ; if ( ( int ) ( s [ i ] ) + add <= ( int ) ( ' z ' ) ) s [ i ] = ( char ) ( ( int ) ( s [ i ] ) + add ) ; else { add = ( ( int ) ( s [ i ] ) + add ) - ( ( int ) ( ' z ' ) ) ; s [ i ] = ( char ) ( ( int ) ( ' a ' ) + add - 1 ) ; } } Console . WriteLine ( s ) ; } public static void Main ( string [ ] args ) { string str = " geeks " ; addFrequencyToCharacter ( str . ToCharArray ( ) ) ; } }
Check if it is possible to reach any point on the circumference of a given circle from origin | C # program for the above approach ; Function to check if it is possible to reach any point on circumference of the given circle from ( 0 , 0 ) ; Stores the count of ' L ' , ' R ' ; Stores the count of ' U ' , ' D ' ; Traverse the string S ; Update the count of L ; Update the count of R ; Update the count of U ; Update the count of D ; Condition 1 for reaching the circumference ; Store the the value of ( i * i ) in the Map ; Check if ( r_square - i * i ) already present in HashMap ; If it is possible to reach the point ( mp [ r_square - i * i ] , i ) ; If it is possible to reach the point ( i , mp [ r_square - i * i ] ) ; If it is impossible to reach ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { static string isPossible ( string S , int R , int N ) { int cntl = 0 , cntr = 0 ; int cntu = 0 , cntd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' L ' ) cntl ++ ; else if ( S [ i ] == ' R ' ) cntr ++ ; else if ( S [ i ] == ' U ' ) cntu ++ ; else cntd ++ ; } if ( Math . Max ( Math . Max ( cntl , cntr ) , Math . Max ( cntu , cntd ) ) >= R ) return " Yes " ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; int r_square = R * R ; for ( int i = 1 ; i * i <= r_square ; i ++ ) { mp . Add ( i * i , i ) ; if ( mp . ContainsKey ( r_square - i * i ) ) { if ( Math . Max ( cntl , cntr ) >= mp [ r_square - i * i ] && Math . Max ( cntu , cntd ) >= i ) return " Yes " ; if ( Math . Max ( cntl , cntr ) >= i && Math . Max ( cntu , cntd ) >= mp [ r_square - i * i ] ) return " Yes " ; } } return " No " ; } static public void Main ( ) { string S = " RDLLDDLDU " ; int R = 5 ; int N = S . Length ; Console . WriteLine ( isPossible ( S , R , N ) ) ; } }
Modify characters of a string by adding integer values of same | C # program for the above approach ; Function to modify a given String by adding ASCII value of characters from a String S to integer values of same indexed characters in String N ; Traverse the String ; Stores integer value of character in String N ; Stores ASCII value of character in String S ; If b exceeds 122 ; Replace the character ; Print resultant String ; Driver Code ; Given Strings ; Function call to modify String S by given operations
using System ; public class GFG { static void addASCII ( char [ ] S , char [ ] N ) { for ( int i = 0 ; i < S . Length ; i ++ ) { int a = ( int ) ( N [ i ] ) - '0' ; int b = ( int ) ( S [ i ] ) + a ; if ( b > 122 ) b -= 26 ; S [ i ] = ( char ) ( b ) ; } Console . Write ( S ) ; } public static void Main ( String [ ] args ) { String S = " sun " , N = "966" ; addASCII ( S . ToCharArray ( ) , N . ToCharArray ( ) ) ; } }