XOR Strings 2

Sort by

recency

|

240 Discussions

|

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

    There is no 'strings_xor' function in the 'Javascript (Node.js)' mode. Is this a bug? What should I debug in corresponing to the test conditions?

  • + 0 comments

    For Python:

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

    For C++, it looks like the submission process is broken for modes C++14/C++20.

    Those modes gave wrong answer for code that was successully submitted in C++11 mode!

  • + 1 comment

    This function performs a bitwise XOR operation on two input strings s and t.

    The XOR operation compares corresponding characters of the two strings:

    - If the characters are the same, it appends '0' to the result string.

    - If the characters are different, it appends '1' to the result string.

    def strings_xor(s, t): res = "" # Initialize an empty result string

    # Loop through each character index in the strings (assumes both strings have the same length)
    for i in range(len(s)):
        if s[i] == t[i]:  
            res += '0'  # If characters at index `i` are the same, append '0'
        else:
            res += '1'  # If characters at index `i` are different, append '1'
    
    return res  # Return the final XOR result string
    

    Input: Two binary strings from the user

    s = input() # First binary string t = input() # Second binary string

    Output: The XOR of the two input strings

    print(strings_xor(s, t))