P0011. Distance of Hamming P95206


Statement
 

pdf   zip

html

The distance of Hamming between two natural numbers is defined as the number of positions in these numbers that have different digits. For instance, the distance of Hamming of 70075 and 774 is 3:

7   0   0   7   5
707   7   4there are 3 differences

Your task is to write a program that reads pairs of natural numbers and prints their Hamming distance and the sum of the digits which are in positions with different digits. In the instance, the sum is (7 + 0) + (0 + 7) + (5 + 4) = 23.

Your program must implement and use the procedure

void calculates(int a, int b, int& dist, int& sum);

that, given two natural numbers |a| and |b|, stores at the output parameter |dist| their Hamming distance, and stores at the output parameter |sum| the sum of the digits which are in positions with different digits.

Input

The input is a sequence of pairs of natural numbers.

Output

For each pair of the input, print its Hamming distance and the sum of the digits which are in positions with different digits in another line.

Observation

Remember to implement |calculates()| recursively. This procedure can not contain loops nor calls to other procedures.

Public test cases
  • Input

    70075 774
    774 70075
    0 99999
    100000 0
    0 0
    1234567 2345678
    

    Output

    3 23
    3 23
    5 45
    1 1
    0 0
    7 63
    
  • Information
    Author
    Professorat de P1
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++