you are doing len - 1 here, right? which means m is the index of the last character of the strings.
then again in line 8 - 9
while m>0:
m=m-1
you are again doing m = m - 1. So, Suppose if len = 2, then m becomes 0 here. means that you will miss m = 1 (the last character).
You are literally forgetting to check the last character of the string here. Your code will fail for simpliest possible inputs or inputs where byang fails to do the sum of the first numbers from the left.
Inputs like these,
n=True
a,b=map(int, input().split())
a=str(a)
b=str(b)
for i in range(1,len(str(min(a,b)))+1):
if int(a[-i])+int(b[-i])>=10:
n=False
break
print('Yes' if n==False else 'No')
My code gets wrong answer only for test case 7, I’ve done everything but still could not solve it, any and all help is welcome, thank you.
a,b = map(str,input().split())
n = min(len(a),len(b))
A = list(a)
A = a[::-1]
B = list(b)
B = b[::-1]
if int(A[0]) + int(B[0]) > 9:
---print("Yes")
---quit()
for i in range(n-1):
---if int(A[i]) + int(B[i]) > 9:
------print("Yes")
------quit()
print("No")
a,b=map(str,input().split())
c=[]
d=[]
for i in range(len(a)):
c.append(int(a[i]))
for i in range(len(b)):
d.append(int(b[i]))
e=c[i]+d[i]
if e>=10:
print('Yes')
break
elif i==len(a)-1 or i==len(b)-1:
print('No')
There is a problem in the condition of while in your code.
The condition will be n!=0 || m!= 0.
Otherwise the first digits of the numbers will remain uncounted.
include <iostream>
using namespace std;
int main() {
string a , b;
cin >> a >> b;
int n = a.size();
for(int i = n ; i >= 0 ; i--){
int x = (a[i]-'0')+(b[i]-'0');
if(x>9){
cout << "Yes"<<endl;
return 0 ;
}
}
cout << "No"<<endl;
}