DOUBT IN CODE (Ultra-Fast-Mathematicians Problem)

#include
using namespace std;

int main() {
int n;
cin>>n;

while(n--)
{
	long long int a,b;
	cin>>a>>b;
	cout<<(a^b)<<"\n";
}
return 0;

}

The answer should come as 00111 for the sample test case, but I am getting the answer as only 111. How do I get to print the leading zeroes?

@pratyushnitdgp19_2c287088d77b5893

Instead of taking input as long long int you can take it as a string.
string a, b, ans;
cin>>a>>b;

Implement your logic and print the final ans string. This way you can print leading zeroes.

#include
using namespace std;

int main() {
int n;
cin>>n;
while(n–)
{
string a,b,res;
cin>>a>>b;

	for(int i=0;i<a.size();i++)
	{
		if(a[i]==b[i])
		res[i]=0;
		else
		res[i]=1;
	}

	cout<<res<<"\n";
}

return 0;

}
Sir this code is not printing any output.

@pratyushnitdgp19_2c287088d77b5893

int main() {
int n;
cin>>n;
while(n–)
{
     string a,b,res;
     cin>>a>>b;
     res = a; // assign result to some initial value else it will be an empty string
     for(int i=0;i<a.size();i++){
		if(a[i]==b[i])
		  res[i]='0'; // it should be '0' not 0
		else
		  res[i]='1'; // it should be '1' not 1
     }
     cout<<res<<"\n";
}

return 0;
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.