help;/

shanker

Well-known member
Joined
Sep 18, 2016
Messages
291
Reaction score
16
Location
Romania
Five distinct numbers are given. Determine the sum of the top 3 of them.

the 5 natural numbers are distinct, ranging from 1 to 10000 inclusive

ex: [font=Menlo, Monaco, Consolas,]1 5 2 3 100[/font]

[font=Menlo, Monaco, Consolas,]output: 108[/font]

[font=Menlo, Monaco, Consolas,]pb source: https://www.pbinfo.ro/?pagina=probleme&id=559[/font]

[font=Menlo, Monaco, Consolas,]it gives me only 40 points[/font]
it fkin works idk why i cant get 100p :/
[shcode=cpp]
#include <iostream>
#include <math.h>

using namespace std;

int main() {
    int X[5];

    cin >> X[0];
    cin >> X[1];
    cin >> X[2];
    cin >> X[3];
    cin >> X[4];


    if (X[0]!=X[1] && X[0]!=X[2] && X[0]!=X[3] && X[0]!=X[4]) {
        if (X[1]!=X[0] && X[1]!=X[2] && X[1]!=X[3] && X[1]!=X[4]) {
            if (X[2]!=X[0] && X[2]!=X[1] && X[2]!=X[3] && X[2]!=X[4]) {
                if (X[3]!=X[0] && X[3]!=X[1] && X[3]!=X[2] && X[3]!=X[4]) {
                    if (X[4]!=X[0] && X[4]!=X[1] && X[4]!=X[2] && X[4]!=X[3]) {

                        int MAX[6];
                        MAX[0] = max(X[0], X[1]);
                        MAX[1] = max(X[2], X[3]);
                        MAX[2] = max(X[4], X[0]);
                        MAX[3] = max(X[4], X[1]);
                        MAX[4] = max(X[4], X[2]);
                        MAX[5] = max(X[4], X[3]);

                        cout << MAX[0] + MAX[1] + MAX[2] << endl;
                    }
                }
            }
        }
    }
}

[/shcode]
 

user88

Well-known member
Joined
Jun 29, 2017
Messages
426
Reaction score
165
Location
LINK CLEO DICE HACK HERE!
what are u try to do? XD

maybe u can just search trough the X array the biggest number, then the sec and third

simply add them to another sum

done.
 

mistery

Well-known member
Joined
Apr 23, 2014
Messages
262
Reaction score
5
maybe only 40 because you are using too many unnecessary things , like math.h or the max function..
try this

Code:
#include <iostream>
using namespace std;
int i,X[5],max1,max2,max3;
int main()
{
    for(i=0;i<=4;i++)
    {cout<<"X["<<i<<"]=";cin>>X[i];}
    max1=X[0];
    for(i=1;i<=4;i++)
        if(X[i]>max1)
            max1=X[i];
    for(i=0;i<=4;i++)
        if(X[i]<max1 && X[i]>max2)
            max2=X[i];
    for(i=0;i<=4;i++)
        if(X[i]<max2 && X[i]>max3)
            max3=X[i];
    cout<<endl<<"Max 1 = "<<max1;
    cout<<endl<<"Max 2 = "<<max2;
    cout<<endl<<"Max 3 = "<<max3;
    cout<<endl<<"Sum = "<<max1+max2+max3;
    return 0;
}
 
Top