Informatică, întrebare adresată de laurachirila5, 9 ani în urmă

Virus

Robespierre managed to find a document which lists the value of Miaurice’s underground business.

It is a long piece of paper on which are written all the integer numbers:
1 2 3 ... 25048

A special solution (named virus) was applied to the paper erasing all the digits “0” from these numbers, living a blank space.
In this way some of the numbers are modified. For example, 860 becomes 86, and 1087 is converted in two distinct numbers: 1 and 87.
The money earned by Miaurice’s gang is the sum of all numbers from the virused paper.

Help Robespierre to find this value.

Example: If on the paper there were initially 11 numbers, the sum will be:
1+2+3+4+5+6+7+8+9+1+11=57.


CUM POT REZOLVA ACEASTA PROBLEMA IN C++ ????
URGENT


artur99: Ești la bilingv? :)))
artur99: Care-s limitele numerelor?

Răspunsuri la întrebare

Răspuns de milumil2000
2
#include <iostream>
using namespace std;

int n=25048, i, j, c, m, v=0;

int main(){
    for(i=1;i<=n;i++){
        j=i;
        m=0;
        while(j){
            c=j%10;
            if(c==0){
                v=v+m;
                m=0;
            }
            else{
                m=10*m+c;
            }
            j=j/10;
        }
        v=v+m;
    }
    cout<<v;
}

evulescumihai11: cfggg
Alte întrebări interesante