I think the method is correct but not getting any output.
Please tell what is the problem in this code?
#include<iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
string a,b;
cin>>a>>b;
string c(a.length(),' ');//initializimg c with space of required length
for(int i=0;i<a.length();i++){
if(a[i]==b[i])
c[i]='0';//= instead of ==
else
c[i]='1';//= instead of ==
}
cout<<c<<endl;
}
return 0;
}
If this resolves your query then please mark it as resolved
Why do we have to create c with a well defined size??
We can simply make a normal string.
Because you are using c[i] to reference i th character which we can only do if it exist .
So either declare string like this or use + or push_back to append in string
1 Like
thank u so much kartik
1 Like