XOR Strings 2

Sort by

recency

|

253 Discussions

|

  • + 0 comments

    bruh what happend to hankerrank it feels like a cheap website it wasn't like this before the code isn't working

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        String str2 = sc.next();
    
        String result = xor(str, str2);
        System.out.println(result);
    
    }
    
    public static String xor(String str, String str2)
    {
        StringBuilder s = new StringBuilder();
        for(int i = 0; i <= str.length() - 1; i+=1)
        {
            int num1 = str.charAt(i) - '0';
            int num2 = str2.charAt(i) - '0';
            s.append(num1 ^ num2);
        }
        return s.toString();
    }
    

    }

  • + 0 comments

    omg. for JAVA you need to go to java 7 and dont touch anything else, but the 3 places that need to be fixed!

    we need to report somehow such awful exercises

  • + 0 comments

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

    return res
    
  • + 1 comment

    I tried to submit the following method: public static void main(String args[] ) throws Exception { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String s = bufferedReader.readLine(), t = bufferedReader.readLine(); System.out.println(IntStream.range(0, s.length()).mapToObj(i -> String.valueOf(s.charAt(i) ^ t.charAt(i))).collect(Collectors.joining()));

    } although it visually presents the same result. It is difficult to understand what the real problem is.

  • + 1 comment

    I have checked multiple times, my logic is correct, the output I am printing is also correct but compiler says wrong answer. Any idea? Compiler Message: Wrong Answer Input (stdin) 10101 00101 Your Output (stdout) 10000 Expected Output 10000