Ultra-fast- Mathematics

code:
#include
#include
#include<stdio.h>
#include
using namespace std;
int main() {
int t;
cin>>t;
while(t–)
{
string num1, num2;
int main_no;
cin>>num1>>num2;

	int i, j ;
	 i= stoi(num1);
	 j=stoi(num2);
     cout<<i<<j<<endl;
	
	main_no =(i ^ j) ;
	
	int digit = (num1.length() > num2.length()) ? num1.length() :  num2.length();
	//std::cout << std::setfill('0') << std::setw(5) << 25;
	cout<<setfill('0')<<setw(digit)<<main_no<<endl;

}
return 0;

}
this is my code but even afer writting cout I am getting no output, why it is so, also suggest me some efficient method to convert string to int as header files and stoi, sscanf are giving run time error

Hello @Divya_321,

  1. It is giving no output because your code is causing TLE.

  2. stoi() function is causing a run-time error because it does not work for the numbers greater than the range of an int.
    You have no need to convert it.

Approach:
As both the strings are of the same length, then start iterating over both the strings from left to right.
Meanwhile, compare their corresponding elements:
if a[i]==b[i]: c+=β€˜0’;
else: c+=β€˜1’;

where c is the output string.

Hope this would help.
Give a like if you are satisfied.

Thank you , but what if I want to store the number in a string or arrays with generated 0s at the beginning and than return that to other function to print inpite of simpling priting 1 or 0 at every step, and what if the string is not of equal length , although here it is same

Hello @Divya_321,

  1. I have not suggested you to print the characters, rather take an empty string (say c) to store result.
    And keep appending the characters of result to it. Hence, forming the result.

  2. If the strings are not of the same length then you can subtract there length (len(a)-len(b)=diff).
    Take the larger string and append diff no. of 1s of that strings from left as it is to the result stringΒ©.
    Example:
    a=101010
    b=0001
    mod(len(a)-len(b))=2
    c="";
    c+=β€œ1”; //1
    c+=β€œ1”; //11
    Now for rest of the string apply the previously mentioned logic.

Hope, it is cleared now.