Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <iostream>
- #define LOG(x) std::cout << (x) << std::endl
- #define MAX_SIZE 50
- struct EuropeanFootballMatches
- {
- char homeTeam[MAX_SIZE];
- char guestTeam[MAX_SIZE];
- int homeTeamGoals = 0;
- int guestTeamGoals = 0;
- EuropeanFootballMatches *next = nullptr;
- };
- bool foo(EuropeanFootballMatches *head, const char teamToProcess[])
- {
- int totalGoals = 0;
- while (head)
- {
- if (strcmp(head->homeTeam, teamToProcess) == 0)
- {
- totalGoals += head->homeTeamGoals;
- if (totalGoals >= 3)
- return true;
- }
- else if (strcmp(head->guestTeam, teamToProcess) == 0)
- {
- totalGoals += head->guestTeamGoals;
- if (totalGoals >= 3)
- return true;
- }
- head = head->next;
- }
- return false;
- }
- int main()
- {
- EuropeanFootballMatches *head = nullptr;
- EuropeanFootballMatches *current = nullptr;
- EuropeanFootballMatches *temp = nullptr;
- current = new EuropeanFootballMatches;
- strcpy(current->homeTeam, "Juve");
- strcpy(current->guestTeam, "Inter");
- current->homeTeamGoals = 3;
- current->guestTeamGoals = 2;
- temp = current;
- head = current;
- current = new EuropeanFootballMatches;
- strcpy(current->homeTeam, "Palermo");
- strcpy(current->guestTeam, "Inter");
- current->homeTeamGoals = 2;
- current->guestTeamGoals = 1;
- temp->next = current;
- temp = current;
- std::cout << foo(head, "Juve");
- std::cout << foo(head, "Inter");
- std::cout << foo(head, "Palermo");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement