0

Why this C code is displaying wrong answer?

//Actually I am solving a beginner Comitative programming problems. //Question link: https://codeforces.com/problemset/problem/61/A //My code: #include <stdio.h> #include <stdlib.h> #include<string.h> #define S 100 int main() { char str1[S];//input string char str2[S];//input string int i,j; scanf(" %s",str1); scanf(" %s",str2); const len=strlen(str1); char str3[len];//output string for(i=0;i<len;i++) { if(str1[i]== str2[i]) { str3[i]='0'; } else { str3[i]='1'; } } printf("%s",str3); return 0; } //Wrong answer on test 3 but it passes the first 2 cases //01110 //str1 //01100 //str2 //00010‼@ //str3, (wrong answer) it outputs additional character as (!!@)

24th May 2021, 9:38 AM
Sandesh Adhikari
Sandesh Adhikari - avatar
4 odpowiedzi
+ 1
You can run loop just for len and print inside loop instead of making new string
24th May 2021, 9:57 AM
YUGRAJ
0
Ok i will try
24th May 2021, 12:41 PM
Sandesh Adhikari
Sandesh Adhikari - avatar
0
Martin Taylor thanks a lot❤️
30th May 2021, 12:34 AM
Sandesh Adhikari
Sandesh Adhikari - avatar