Total number of "lucky" tickets in given range.

Hello everyone! I would be very greatfull if someone could help me. I was given C++ task. Could anyone give me some ideas of writing the code. The problem goes here…

I was given some set of tickets. First ticket is numbered M, last – N.
M and N have the following limitations: 10000000 ? M < N ? 99999999.
Your task is to identify total number of “lucky” tickets in the given range.
We say that ticket is “lucky”, if the sum of first 4 digits equals to the sum of last 4 digits.

Input:
Input contains first and the last possible number of the tickets.

Output
Output total number of “lucky” tickets in given range.

Samples:

Input N1:

11111110

11111112

Output N1:

1

Input N2:

10000000
99999999

Output N2:

4379055
1
2
3
4
5
6
7
8
unsigned long first, last;
std::cin >> first >> last;
unsigned int lucky(0);
while(first <= last) {
    if (/* number is lucky */)
        ++lucky;
}
std::cout << lucky;
Last edited on
Topic archived. No new replies allowed.