Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct Time {
- int hours;
- int minutes;
- int seconds;
- };
- struct Runner {
- char name[20];
- int age;
- struct Time start_time;
- struct Time end_time;
- };
- int compareTime(struct Time t1, struct Time t2) {
- if (t1.hours > t2.hours) {
- return -1;
- } else if (t1.hours < t2.hours) {
- return 1;
- } else {
- if (t1.minutes > t2.minutes) {
- return -1;
- } else if (t1.minutes < t2.minutes) {
- return 1;
- } else {
- if (t1.seconds > t2.seconds) {
- return -1;
- } else if (t1.seconds < t2.seconds) {
- return 1;
- } else {
- return 0;
- }
- }
- }
- }
- struct Time calculateDifference(struct Time t1, struct Time t2) {
- struct Time result;
- result.hours = t2.hours - t1.hours;
- result.minutes = t2.minutes - t1.minutes;
- result.seconds = t2.seconds - t1.seconds;
- if (result.seconds < 0) {
- result.minutes--;
- result.seconds += 60;
- }
- if (result.minutes < 0) {
- result.hours--;
- result.minutes += 60;
- }
- return result;
- }
- void winner(struct Runner runner[]) {
- for (i = 0; i < 19; i++) {
- for (j = 0; j < 19 - i; j++) {
- if (compareTime(calculateDifference(runner[j].start_time, runner[j].end_time), calculateDifference(runner[j + 1].start_time, runner[j + 1].end_time)) == -1) {
- struct Runner temp;
- temp = runner[j];
- runner[j] = runner[j + 1];
- runner[j + 1] = temp;
- }
- }
- }
- printf("%s\n", runner[0].name);
- }
- int main() {
- struct Runner runner[20];
- int i, j;
- for (i = 0; i < 20; i++) {
- scanf("%s", &runner[i].name);
- scanf("%d", &runner[i].age);
- scanf("%d:%d:%d", &runner[i].start_time.hours, &runner[i].start_time.minutes, &runner[i].start_time.seconds);
- scanf("%d:%d:%d", &runner[i].end_time.hours, &runner[i].end_time.minutes, &runner[i].end_time.seconds);
- }
- winner(runner);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement