vendredi 24 mai 2019

How to find max sum from list of nubmers

I am finding max sum from inputed numbers.

Find maximum sum which formed by given set of numbers but to make sum use number which font have repeated digits to another number.

eg. inputed cases numbers n=4

1 2 3 - > 6 ( no repeated ) 1+2+3
3  30  8  1 - > 39 ( here 3  is repeated ) 30+8+1
11 21 31 41 -> 41   ( here 1 is repeated to all so max number will print ) 41
11 5  45 88  - > 99 ( here 5 is repeated ) 11+88



int sum(int Ticket[], int n)
{
    int max;
    int abc;
    for (int i = 0; i <= n; i++) {
        for (int k = 0; k <= n; k++) {
            abc = Ticket[i];
            max = Ticket[i] + Ticket[i]
                int len = to_string(abc).length();

            for (int j = 0; j <= len; j++) {
                std::string nstr = std::to_string(abc);
                std::cout << "->" << nstr[j];
            }
        }
    }
return max;
}
int main()
{ 
       // n total number of array or numbers
        int max = sum(Ticket, n);
}

Aucun commentaire:

Enregistrer un commentaire