Cod sursa(job #470239)

Utilizator skyelHighScore skyel Data 12 iulie 2010 15:16:54
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <stdio.h>

#include <stdlib.h>
using namespace std;
#include <algorithm>
#include <vector>

typedef struct
        {
        int energy;
        int cost;
        float sort;      
              
        }my_struct;

bool sorting(my_struct a, my_struct b)
     {
     return a.sort > b.sort;                  
     }        

int main()
{
    int n,target;
    vector<my_struct> array;
    scanf("%d %d",&n,&target);
    for ( int i = 0; i < n; ++i)
    {
        my_struct atom;
        scanf("%d %d",&atom.energy,&atom.cost);
        atom.sort = ((float)atom.energy)/((float)atom.cost);
        array.push_back(atom);
    }
    sort(array.begin(),array.end(),sorting);
    for (int i = 0; i < n; ++i)
    {
        my_struct atom;
        atom = array[i];
        printf("%d %d %f",atom.energy,atom.cost,atom.sort);
       
    }
    
    return 0;
    
}