We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The C code is almost blank, just the main function and not the strings_xor function. So i had to create the code by myself so of course it doesn't work since the main condition isn't satisfied (just 3 lines)...
C implementation :
#include<math.h>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<assert.h>#include<limits.h>#include<stdbool.h>char*strings_xor(char*input1,char*input2){char*answer=malloc(strlen(input1)*sizeof(char));for(inti=0;i<strlen(answer);++i){answer[i]='0';}// We read the consolescanf("%s\n",input1);scanf("%s\n",input2);// We calculate the XOR relation between the inputsfor(inti=0;i<strlen(input1);++i){if(input1[i]!=input2[i]){answer[i]='1';}if(input1[i]==input2[i]){answer[i]='0';}}returnanswer;}intmain(){// We create three pow(10,4)+1 length string variables to stock the inputs and to create the answerchar*input1=malloc((pow(10,4)+1)*sizeof(char));char*input2=malloc((pow(10,4)+1)*sizeof(char));char*answer=strings_xor(input1,input2);// We display the answerprintf("%s",answer);free(input1);free(input2);free(answer);`return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
XOR Strings
You are viewing a single comment's thread. Return to all comments →
The C code is almost blank, just the main function and not the strings_xor function. So i had to create the code by myself so of course it doesn't work since the main condition isn't satisfied (just 3 lines)...
C implementation :