Sort by

recency

|

86 Discussions

|

  • + 0 comments

    Here is my c++ working solution, you can watch the explanation here : https://youtu.be/eCWFW0phR-4.

    Keep in mind that it's not just about getting the right answer, it's also about making at most three changes, so an extra space on a new line will cause your code to fail, you can get a demo in the video above.

    string strings_xor(string s, string t) {
    
        string res = "";
        for(int i = 0; i < s.size(); i++) {
            if(s[i] == t[i])
                res += '0';
            else
                res += '1';
        }
    
        return res;
    }
    
  • + 0 comments

    I am not an experienced programmer, but I think that there are some errors in the code. If you have doubts, then you'd better contact these data governance services for software development guidance. Here's a plain language explanation of what the code is trying to do and the issues with it:

    The program starts by including necessary headers such as , , , , and . These facilitate various functionalities like mathematical operations, input/output operations, and using vectors.

    The strings_xor function is defined to take two strings, s and t, and it initializes an empty string res to store the result.

    The function then loops through each character of the strings s and t. It checks if the characters at the same position in both strings are the same.

    There's a logical error in the if condition within the loop: it uses a single equals sign (=) which is an assignment operator, not a comparison operator. This needs to be a double equals sign (==) to correctly compare the characters.

    Based on the comparison, if the characters are the same, it appends '0' to the res string. If they are different, it appends '1' to the res string.

    However, another issue is that instead of appending to the res string (res += '0'; or res += '1';), the code mistakenly assigns '0' or '1' directly to res, which means only the result of the last comparison will be stored, not the cumulative result.

    The function ends by returning the res string, which is intended to be the XOR result of the two input strings.

    In the main function, the program reads two strings s and t from the user input, then calls the strings_xor function with these strings, and prints the result.

    To correct the function:

    Replace if(s[i] = t[i]) with if(s[i] == t[i]) to fix the comparison. Change res = '0'; and res = '1'; to res += '0'; and res += '1'; respectively, to correctly append each result to res. These corrections will ensure that the function properly calculates the XOR of two binary strings character by character, appending the result of each comparison to the output string.

  • + 0 comments

    why is my code not working i mean i am getting the right answer but the compiler says i am wrong.

    include

    include

    using namespace std; int main(){ string str1,str2; cin>>str1>>str2; for (int i = 0; i < str1.length(); i++) { if (str1[i]=='0' && str2[i]=='1') { cout<<1; } else if (str1[i]=='1' && str2[i]=='0') { cout<<1; } else { cout<<0; }
    } return 0; }

  • + 1 comment

    Here is my python working debugged solution -->

    def strings_xor(s, t): res = "" for i in range(len(s)): if s[i] == t[i]: res += '0'; else: res += '1';

    return res
    

    s = input() t = input() print(strings_xor(s, t))

  • + 0 comments

    In C++14 it seems to be broken, example is correct still returns wrong. Same answer in C++11 gives correct feedback.