Find one extra character in a string | CPP program to find extra character in one string ; result store the result ; traverse string A till end and xor with res ; xor with res ; traverse string B till end and xor with res ; xor with res ; print result at the end ; given string
#include <iostream> NEW_LINE using namespace std ; char findExtraCharcter ( string strA , string strB ) { int res = 0 , i ; for ( i = 0 ; i < strA . length ( ) ; i ++ ) { res ^= strA [ i ] ; } for ( i = 0 ; i < strB . length ( ) ; i ++ ) { res ^= strB [ i ] ; } return ( ( char ) ( res ) ) ; } int main ( ) { string strA = " abcd " ; string strB = " cbdad " ; cout << findExtraCharcter ( strA , strB ) ; return 0 ; }