Help in the code (BUGCAL)

What’s wrong with my solution for BUGCAL?

This also satisfies the constraints!
Any help would be appreciated! Thanks in advance!

Your code is failing for this test case :

1

515 515

Your O/P : 020 (WA)
Correct O/P : 20

Here is your AC code :stuck_out_tongue:

    #include <iostream>
#include <bits/stdc++.h>
#include <string> 
 
using namespace std;
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;
	cin>>T;
	while(T--)
	{
	    long long a,b;
	    cin>>a>>b;
	    string str;
	    while(a>0||b>0)
	    {
	        str+=to_string((a%10+b%10)%10);
	        a/=10;
	        b/=10;
	    }
	    reverse(str.begin(),str.end());
	    long long i;
	    int flag=1;
	    for(i=0;i<str.length();i++)
	    {
	        if(str[i]!='0')
	        {
	            flag=0;
	            break;
	        }
	    }
	    if(flag==1)
	        cout << "0" << endl;
	    else 
	        cout <<str.substr(i) << endl;
	}
	return 0;
}
1 Like