Add up digits multiplied by their position

Write a program that reads numbers from the input, and outputs the
result of adding each digit multiplied by its position. We consider the
most significant digit to be at position 1, the second most significant
digit to be at position 2, and so on and so forth.

For example, given 785902, the program will print 86, which is the
result of evaluating 1 × 7 + 2 × 8 + 3 × 5 + 4 × 9 + 5 × 0 + 6 × 2.

Input

The input has an arbitrary number of cases. Each one is a positive
natural number in one line.

Output

For each case, the output contains a line with the corresponding result
of adding digits multiplied by their positions.

Observation

Massive storage solutions are not accepted (like strings or vectors).
Read numbers from the input into variables of type int; for instance,
with cin  > > a, and solve the problem operating with integers using +,
-, , /, and %.

Evaluation over 10 points:

- Slow solution: 5 points.

- Fast solution: 10 points.

We understand as fast solution one which is correct, has linear cost and
passes the public and private tests. We understand as slow solution one
which is not fast, but it is correct and passes the public tests.

Problem information

Author: PRO1

Generation: 2026-01-25T22:58:29.390Z

© Jutge.org, 2006–2026.
https://jutge.org
