Check whether the string S1 can be made equal to S2 with the given operation | C # implementation of the approach ; Function to return the string formed by the odd indexed characters of s ; Function to return the string formed by the even indexed characters of s ; Function that returns true if s1 can be made equal to s2 with the given operation ; Get the string formed by the even indexed characters of s1 ; Get the string formed by the even indexed characters of s2 ; Get the string formed by the odd indexed characters of s1 ; Get the string formed by the odd indexed characters of s2 ; Sorting all the lists ; If the strings can be made equal ; Driver Code
using System ; class GFG { static string partOdd ( string s ) { string st = " " ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( i % 2 != 0 ) st += s [ i ] ; } return st ; } static string partEven ( string str ) { string s = " " ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( i % 2 == 0 ) s += str [ i ] ; } return s ; } static bool canBeMadeEqual ( string s1 , string s2 ) { char [ ] even1 = partEven ( s1 ) . ToCharArray ( ) ; char [ ] even2 = partEven ( s2 ) . ToCharArray ( ) ; char [ ] odd1 = partOdd ( s1 ) . ToCharArray ( ) ; char [ ] odd2 = partOdd ( s2 ) . ToCharArray ( ) ; Array . Sort ( even1 ) ; Array . Sort ( even2 ) ; Array . Sort ( odd1 ) ; Array . Sort ( odd2 ) ; string even_s1 = new string ( even1 ) ; string even_s2 = new string ( even2 ) ; string odd_s1 = new string ( odd1 ) ; string odd_s2 = new string ( odd2 ) ; if ( even_s1 . Equals ( even_s2 ) && odd_s1 . Equals ( odd_s2 ) ) return true ; return false ; } public static void Main ( ) { string s1 = " cdab " ; string s2 = " abcd " ; if ( canBeMadeEqual ( s1 , s2 ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }