Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <string.h>
  2. #include <iostream>
  3.  
  4. #define LOG(x) std::cout << (x) << std::endl
  5. #define MAX_SIZE 50
  6.  
  7. struct EuropeanFootballMatches
  8. {
  9. char homeTeam[MAX_SIZE];
  10. char guestTeam[MAX_SIZE];
  11. int homeTeamGoals = 0;
  12. int guestTeamGoals = 0;
  13.  
  14. EuropeanFootballMatches *next = nullptr;
  15. };
  16.  
  17. bool foo(EuropeanFootballMatches *head, const char teamToProcess[])
  18. {
  19. int totalGoals = 0;
  20.  
  21. while (head)
  22. {
  23. if (strcmp(head->homeTeam, teamToProcess) == 0)
  24. {
  25. totalGoals += head->homeTeamGoals;
  26. if (totalGoals >= 3)
  27. return true;
  28. }
  29. else if (strcmp(head->guestTeam, teamToProcess) == 0)
  30. {
  31. totalGoals += head->guestTeamGoals;
  32. if (totalGoals >= 3)
  33. return true;
  34. }
  35.  
  36. head = head->next;
  37. }
  38.  
  39. return false;
  40. }
  41.  
  42. int main()
  43. {
  44. EuropeanFootballMatches *head = nullptr;
  45. EuropeanFootballMatches *current = nullptr;
  46. EuropeanFootballMatches *temp = nullptr;
  47.  
  48. current = new EuropeanFootballMatches;
  49. strcpy(current->homeTeam, "Juve");
  50. strcpy(current->guestTeam, "Inter");
  51. current->homeTeamGoals = 3;
  52. current->guestTeamGoals = 2;
  53. temp = current;
  54. head = current;
  55.  
  56. current = new EuropeanFootballMatches;
  57. strcpy(current->homeTeam, "Palermo");
  58. strcpy(current->guestTeam, "Inter");
  59. current->homeTeamGoals = 2;
  60. current->guestTeamGoals = 1;
  61. temp->next = current;
  62. temp = current;
  63.  
  64. std::cout << foo(head, "Juve");
  65. std::cout << foo(head, "Inter");
  66. std::cout << foo(head, "Palermo");
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement