1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
return 0;
int n, i, j;
float pl, pd, pr, maxPr, maxPd;
float poids[n], prix[n];
int x[n];
cout << "Combien d'objets ? " << endl;
cin >> n;
cout << "Quel est le poids maximum du sac ? "<< endl;
cin >> pl;
for (i = 1, i < n, i++ ) {
cout << "Entrez le poids du colis n°: " << i << endl;
cin >> poids[i] << endl;
cout << "Entrez le prix du colis n° " << i << endl;
}
pd = 0;
pr = 0;
maxPr = 0
for (j = 1, j < n, j++){
for ( i= j, i < n, i++){
if (pd + poids[i]] <= pl){
x[i] = 1;
pd = pd + poids [i];
pr = pr + prix[i];
}
else {
x[i] = 0;
pd = pd;
pr = pr;
}
}
si (pr >= maxPr){
maxPd = pd;
maxPr = pr;
}
system("PAUSE");
return EXIT_SUCCESS;
}
} |
Partager