The problem is from codeforces: http://www.codeforces.com/problemset/problem/75/A
The input two numbers can be held by 32-bit signed integer. Therefore, it is unnecessary to use arrays to represent numbers as strings. The problem is to check if after removing zeros, the equations are correct. A straight implementation is easy in Python.
It is worth to note that in Python, the following comparison returns false. The string comparing to the integer, unlike VBScript, is not converted automatically.
print '1234' == 1234
For example, in VBScript, the following prints True
1 | msgbox "1234" = 1234 |
msgbox "1234" = 1234
The Python solution is presented below, which accepts the input as string, removing zeros, and converting back to integers.
#!/usr/bin/env python a = raw_input() b = raw_input() c = int(a) + int(b) aa = a.replace('0', '') bb = b.replace('0', '') cc = int(str(c).replace('0', '')) dd = int(aa) + int(bb) print "YES" if dd == cc else "NO"
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: Codeforces: A. Soft Drinking
Next Post: Number-guessing game in Windows Batch Programming