Merge lp:~yani-kathy/marathon/the_trip into lp:marathon

Proposed by Yanina Aular (Vauxoo)
Status: Merged
Merged at revision: 31
Proposed branch: lp:~yani-kathy/marathon/the_trip
Merge into: lp:marathon
Diff against target: 61 lines (+16/-14)
1 file modified
the_trip/trip.cpp (+16/-14)
To merge this branch: bzr merge lp:~yani-kathy/marathon/the_trip
Reviewer Review Type Date Requested Status
Yanina Aular (Vauxoo) (community) Approve
Review via email: mp+190782@code.launchpad.net

Description of the change

Listo ejercicio de "El viajero" 10137 The trip, en la uva

To post a comment you must log in.
Revision history for this message
Yanina Aular (Vauxoo) (yanina-aular) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'README.txt'
2=== modified file 'the_trip/a.out'
3Binary files the_trip/a.out 2013-10-11 13:12:12 +0000 and the_trip/a.out 2013-10-12 03:10:02 +0000 differ
4=== modified file 'the_trip/trip.cpp'
5--- the_trip/trip.cpp 2013-10-11 13:12:12 +0000
6+++ the_trip/trip.cpp 2013-10-12 03:10:02 +0000
7@@ -1,38 +1,40 @@
8 #include <iostream>
9 #include <stdio.h>
10+#include <cstdio>
11+#include <cmath>
12+#define MAX(a,b) (a < b ? b : a)
13
14 using namespace std;
15
16 int main(){
17 int i, resu;
18- double cant, gastos[1001], total, total2, result, result2;
19+ double cant, gastos[1001], total, total1, total2, result1, result2;
20
21 cin >> cant;
22 while(cant != 0.0){
23 total = 0.0;
24- result = 0.0;
25+ total1 = 0.0;
26+ total2 = 0.0;
27+ result1 = 0.0;
28+ result2 = 0.0;
29 for(i = 0; i < cant; i++){
30 cin >> gastos[i];
31 total+= gastos[i];
32 }
33- total = total / cant;
34- resu = total * 100;
35- total = (float) resu / 100;
36- total2 = (float) resu / 100;
37- total2+=0.01;
38+
39+ total1 = ceil(total/cant*100)/100;
40+ total2 = floor(total/cant*100)/100;
41+
42 for(i = 0; i < cant; i++){
43- if( gastos[i] >= total ){
44- cout << gastos[i] << " - " << total << " + " << result << endl;
45- //resu = result * 100;
46- //result = (float) resu / 100;
47- result = ( gastos[i] - total ) + result;
48+ if( gastos[i] >= total1 ){
49+ result1 = (gastos[i] - total1) + result1;
50 }
51 else{
52- result =
53+ result2 = (total2 - gastos[i]) + result2;
54 }
55 }
56 cout << "$";
57- printf("%.2f",result);
58+ printf("%.2f",MAX(result1, result2));
59 cout << endl;
60 cin >> cant;
61 }

Subscribers

People subscribed via source and target branches

to all changes: