LT02-Editorial

Problem Link

Loop Through

Author:pskalbhav1

Difficulty

EASY

Prerequisites

Implementation

Problem Statement

Arthur and George were two highly renowned Brooklyn detectives. One day they were asked to interrogate Jeremy who was a criminal mastermind. Jeremy said that the information the detectives wanted was all stored on a disk and the information was encrypted. Each word was associated with a MATHEMATHICAL EQUATION (A+B = C), that word was only a part of the message if it held true without the zeros.

Solution

 #include<bits/stdc++.h>
 using namespace std;

 int removeZeros(int num) {
    int ret = 0;
    int ten = 1;
   while (num) {
        int dig = num % 10;
       num /= 10;
       if (dig) {
          ret += dig * ten;
          ten *= 10;
      }
   }
   return ret;
}

int main() {
   int a, b, c;
   cin >> a >> b;
   c = a + b;
   a = removeZeros(a);
   b = removeZeros(b);
   c = removeZeros(c);
   if (a + b == c)
        cout << "YES" << endl;
   else
       cout << "NO" << endl;
   return 0;
}