why my code is partially correct (subtask1 is correct but not subtask2)
here is my code -
#include
using namespace std;
int main(void) {
int t;
cin>>t;
while(t–){
int a,b,sum;
cin>>a>>b;
if((a%10+b%10) >= 10){
sum = a+b-10;
}
else{
sum = a+b;
}
cout<<sum<<endl;
}
return 0;
}
https://www.codechef.com/viewsolution/33142823
my test cases and constraint one is working but subtask 2 isn’t pls help
Also when i removed my sum array and instead used res=res+sum*pow(10,i);
it works …WHY?
https://www.codechef.com/viewsolution/33142823
this is the one which works .I dont understand what difference does the array make to print WA
can i know what is wrong in this code
cook your dish here
t=int(input())
while t>0:
a,b=map(int,input().split())
l1=[]
l2=[]
l3=[]
while a>0:
l1.append(a%10)
a=int(a/10)
while b>0:
l2.append(b%10)
b=int(b/10)
while len(l1)<len(l2):
l1.append(0)
while len(l2)<len(l1):
l2.append(0)
for i in range(len(l1)):
x=(l1[i]+l2[i])%10
l3.append(x)
l3.reverse()
for i in l3:
print(i,end="")
print()
t-=1
sar_1
February 4, 2021, 5:27am
26
Step- Coders I am stuck !!! help me
https://www.codechef.com/viewsolution/42220470
giving partial marks …
Thanks in advance…
couldn’t pass subtask 2
#include<string>
using namespace std;
int main() {
int a,b,t,x,y;
cin>>t;
while(t--)
{
cin>>a>>b;
string a_str= to_string(a);
string b_str= to_string(b);
int sa = a_str.length();
int sb = b_str.length();
int aa[sa],bb[sb];
for(int i = 0 ; i<sa ; ++i)
{
aa[i] = a % 10;
a/=10;
}
for(int i = 0 ; i<sb ; ++i)
{
bb[i] = b % 10;
b/=10;
}
x = (sb<=sa) ? sb : sa ;
y = (sb>=sa) ? sb : sa ;
int sum[y];
for(int i = 0 ; i<x ; ++i)
{
if( (aa[i]+bb[i]) > 9) sum[i] = ( aa[i] + bb[i]) - 10 ;
else sum[i] = aa[i] + bb[i] ;
}
if ( x != y) {
for(int i = x ; i<y ; ++i)
{
sum[i] = (sa>sb) ? aa[i] : bb[i] ;
}
}
for(int i = y-1 ; i>=0 ; --i) cout<<sum[i];
cout<<endl;
}
return 0;
}```