Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- string IntToString(int a)
- {
- string res = "";
- while (a)
- {
- res += a % 10 + '0';
- a /= 10;
- }
- reverse(res.begin(), res.end());
- return res.length() > 0 ? res : "0";
- }
- string Type(int t)
- {
- return t ? "Slat" : "Sweet";
- }
- class Cookie
- {
- private:
- string name;
- int weight;
- int type = 0;//0 - сладкое
- string producer;
- static int count1;
- static int count2;
- public:
- Cookie() {};
- Cookie(string name, int weight, string producer, int type = 0)
- {
- this->name = name;
- this->weight = weight;
- this->producer = producer;
- this->type = type;
- if (type == 1)
- count2++;
- else
- count1++;
- }
- void setName(string name) { this->name = name; }
- void setWeight(int weight) { this->weight = weight; }
- void setType(int type)
- {
- if (this->type == 0)
- count1--;
- else
- count2--;
- if (type == 0)
- count1++;
- else
- count2++;
- this->type = type;
- }
- void setProducer(string producer) { this->producer = producer; }
- string ToPrint()
- {
- return name + " " + IntToString(weight) + " " + producer + " " + Type(type) + "\n";
- }
- bool operator !=(Cookie object)
- {
- if (this->producer != object.producer)
- return true;
- if (this->type != object.type)
- return true;
- if (this->name != object.name)
- return true;
- if (this->weight != object.weight)
- return true;
- return false;
- }
- bool operator <(Cookie object)
- {
- if (this->producer < object.producer)
- return true;
- if (this->producer == object.producer && this->type > object.type)
- return true;
- if (this->producer == object.producer && this->type == object.type &&
- this->name < object.name)
- return true;
- if (this->producer == object.producer && this->type == object.type &&
- this->name == object.name && this->weight > object.weight)
- return true;
- return false;
- }
- static string Count()
- {
- return "Sweet : " + IntToString(count1) + "\nSalt : " + IntToString(count2) + "\n";
- }
- };
- int Cookie::count1 = 0;
- int Cookie::count2 = 0;
- int main()
- {
- //массив из 5 элементов класса
- int n = 5;
- Cookie * a = new Cookie[5];
- for (int i = 0; i < n; ++i)
- {
- string name, prod;
- int w, t;
- in >> name >> w >> prod >> t;
- a[i] = Cookie(name, w, prod, t);
- }
- out << Cookie::Count();
- // соритровка, проверяем оператор <
- for (int i = 0; i < n; ++i)
- for (int j = n - 1; j > i; --j)
- if (a[j] < a[j - 1])
- {
- Cookie temp = a[j];
- a[j] = a[j - 1];
- a[j - 1] = temp;
- }
- for (int i = 0; i < n; ++i)
- out << a[i].ToPrint();
- out << "\n";
- Cookie b = Cookie("Drow", 222, "Anger");
- Cookie c = Cookie("Drow", 444, "Anger");
- out << (b != c ? "true" : "false") << "\n";
- out << "\n" << Cookie::Count() << "\n";
- b.setType(1);
- c.setType(1);
- c.setWeight(222);
- out << (b != c ? "true" : "false") << "\n";
- out << "\n" << Cookie::Count() << "\n";
- /*
- Hleo 500 Forest 1
- Lego 230 QweenP 0
- DrowF 222 Anger 1
- LoGo 1999 Soft 0
- Drefer 124 Slada 1
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement