-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
doremi
committed
May 29, 2012
1 parent
0309a17
commit 6e661a1
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,5 @@ class | |
sleep | ||
clock | ||
ptr | ||
count | ||
count | ||
analysis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <stdio.h> | ||
#include <vector> | ||
#include <time.h> | ||
#include <stdint.h> | ||
|
||
using namespace std; | ||
|
||
struct Record { | ||
int time; | ||
int meter; | ||
}; | ||
|
||
vector<Record> days[2]; | ||
|
||
void make_record(int day, int time, int meter) | ||
{ | ||
Record record; | ||
record.time = time; | ||
record.meter = meter; | ||
days[day].push_back(record); | ||
} | ||
|
||
void list_day(int day) | ||
{ | ||
printf("=== Day %d ===\n", day+1); | ||
auto it = days[day].begin(); | ||
for (; it != days[day].end(); ++it) { | ||
printf("Time: %02d, meter: %d\n", it->time, it->meter); | ||
} | ||
} | ||
|
||
void analysis() | ||
{ | ||
int day = 0; | ||
for (uint32_t i = 1; i < days[day].size(); ++i) { | ||
Record prev = days[day][i-1]; | ||
Record curr = days[day][i]; | ||
printf("ave time: %d, avg meter: %f\n", | ||
(curr.time+prev.time)/2, (double)(curr.meter-prev.meter)/((curr.time-prev.time)*60)); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
make_record(0, 8, 5); | ||
make_record(0, 12, 10); | ||
make_record(0, 19, 20); | ||
make_record(0, 22, 25); | ||
list_day(0); | ||
|
||
analysis(); | ||
|
||
return 0; | ||
} |