Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct Time {
  4. int hours;
  5. int minutes;
  6. int seconds;
  7. };
  8.  
  9. struct Runner {
  10. char name[20];
  11. int age;
  12. struct Time start_time;
  13. struct Time end_time;
  14. };
  15.  
  16. int compareTime(struct Time t1, struct Time t2) {
  17. if (t1.hours > t2.hours) {
  18. return -1;
  19. } else if (t1.hours < t2.hours) {
  20. return 1;
  21. } else {
  22. if (t1.minutes > t2.minutes) {
  23. return -1;
  24. } else if (t1.minutes < t2.minutes) {
  25. return 1;
  26. } else {
  27. if (t1.seconds > t2.seconds) {
  28. return -1;
  29. } else if (t1.seconds < t2.seconds) {
  30. return 1;
  31. } else {
  32. return 0;
  33. }
  34. }
  35. }
  36. }
  37.  
  38. struct Time calculateDifference(struct Time t1, struct Time t2) {
  39. struct Time result;
  40. result.hours = t2.hours - t1.hours;
  41. result.minutes = t2.minutes - t1.minutes;
  42. result.seconds = t2.seconds - t1.seconds;
  43. if (result.seconds < 0) {
  44. result.minutes--;
  45. result.seconds += 60;
  46. }
  47. if (result.minutes < 0) {
  48. result.hours--;
  49. result.minutes += 60;
  50. }
  51. return result;
  52. }
  53.  
  54. void winner(struct Runner runner[]) {
  55. for (i = 0; i < 19; i++) {
  56. for (j = 0; j < 19 - i; j++) {
  57. if (compareTime(calculateDifference(runner[j].start_time, runner[j].end_time), calculateDifference(runner[j + 1].start_time, runner[j + 1].end_time)) == -1) {
  58. struct Runner temp;
  59. temp = runner[j];
  60. runner[j] = runner[j + 1];
  61. runner[j + 1] = temp;
  62. }
  63. }
  64. }
  65.  
  66. printf("%s\n", runner[0].name);
  67. }
  68.  
  69. int main() {
  70. struct Runner runner[20];
  71. int i, j;
  72.  
  73. for (i = 0; i < 20; i++) {
  74. scanf("%s", &runner[i].name);
  75. scanf("%d", &runner[i].age);
  76. scanf("%d:%d:%d", &runner[i].start_time.hours, &runner[i].start_time.minutes, &runner[i].start_time.seconds);
  77. scanf("%d:%d:%d", &runner[i].end_time.hours, &runner[i].end_time.minutes, &runner[i].end_time.seconds);
  78. }
  79.  
  80. winner(runner);
  81.  
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement