algorithm - The use of XOR for removing character from string and finding duplicates -
the following questions based on use of xor :
given string of integers. task @ hand remove given character string. tried using xor solve it. eg
char str[] = "123456"
. remove4.
xor given character entire string. character vanishes.xor = (1^2^3^4^5^6) ^ 4
however left xor of remaining characters.
xor = (1^2^3^5^6)
is there method individual characters back?
i need find , remove elements have duplicates (including elements themselves)
eg. = {1,9,8,2,2} output should {1,9,8} after removal
however fail since 1^9 = 8. hence (1^9)^8^2^2 gives empty array. there alternative using xor itself?
int num=4; for(i=0;i<strlen(str);i++) { if(((str[i]-'0')^num) == 0) remove_number(i); }
Comments
Post a Comment