Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- using namespace std;
- class Person{
- public:
- string email;
- string name;
- string surname;
- Person() = default;
- Person(const char* email, const char* name, const char* surname){
- this->email = email;
- this->name = name;
- this->surname = surname;
- }
- };
- class Following{
- public:
- Person* follower;
- Person* follows;
- Following() = default;
- Following(Person* bjacz, Person* mastier){
- this->follower = bjacz;
- this->follows - mastier;
- }
- };
- class SocialGraph{
- public:
- list <Person> people;
- list <Following> foll;
- bool addPerson(const char* email, const char* name, const char* surname){
- for(auto person:people){
- if (person.email == email){
- return false;
- }
- }
- this->people.emplace_back(Person(email,name,surname));
- }
- bool removePerson(const char* email){
- for (auto i = foll.begin(); foll.end()!=i; ++i){
- if (((*i).follows->email == email || (*i).follower->email == email)){
- i = foll.erase(i);
- }
- }
- for (auto i = people.begin(); people.end()!=i; ++i){
- if ((*i).email == email){
- i = people.erase(i);
- }
- }
- }
- Person* findPerson(const char* email){
- for(auto i = people.begin(); people.end()!=i; ++i){
- if ((*i).email == email){
- return &(*i);
- }
- }
- }
- bool addFollower(const char* emailTo,const char* emailFrom){
- for(auto follow:foll) {
- if (follow.follower->email == emailFrom && follow.follows->email == emailTo) {
- return false;
- }
- }
- Following abc;
- abc.follower = findPerson(emailFrom);
- abc.follows = findPerson(emailTo);
- foll.push_back(abc);
- return true;
- }
- bool unfollow(const char* emailTo,const char* emailFrom){
- for(auto i = foll.begin(); foll.end()!=i; ++i){
- if ((*i).follower->email == emailFrom && (*i).follows->email == emailTo){
- i = foll.erase(i);
- }
- }
- }
- void printPeople(){
- for(auto person:people){
- cout << "name: " << person.name << "\nsurname: " << person.surname << "\nemail: " << person.email;
- cout << "\n___________________________________________\n";
- }
- };
- void printFollowers(){
- for(auto i = foll.begin(); foll.end()!=i; ++i){
- cout << (*i).follower->name << " -> " << (*i).follows->name << "\n";
- }
- }
- };
- int main() {
- SocialGraph a;
- a.addPerson("obajtekmagda@gmail.com","Magdalena","Obajtek");
- a.addPerson("aaaaaaaaaa@gmail.com","Aaaaa","Bbbbbbb");
- a.addPerson("ccccccccccc@gmail.com","Ccccc","Dddddddddddd");
- a.printPeople();
- a.addFollower("obajtekmagda@gmail.com","ccccccccccc@gmail.com");
- cout << "\n\n";
- a.printFollowers();
- a.unfollow("obajtekmagda@gmail.com","ccccccccccc@gmail.com");
- a.printFollowers();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement