Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <iomanip>
- class File {
- public:
- std::string catalog;
- std::string name;
- std::string extension;
- std::string create_date;
- std::string create_time;
- bool is_del;
- int sec_cnt;
- bool operator==(const File &other) {
- return (this->catalog == other.catalog && this->name == other.name
- && this->extension == other.extension && this->create_date == other.create_date &&
- this->create_time == other.create_time && this->is_del == other.is_del && this->sec_cnt == other.sec_cnt);
- }
- friend std::ostream& operator<< (std::ostream &out, const File &f);
- friend std::istream& operator>> (std::istream &in, File &f);
- };
- std::ostream& operator<< (std::ostream &out, const File &f) {
- out << f.catalog << "\n";
- out << f.name << " " << f.extension << " " << f.create_date << " " << f.create_time << "\n";
- out << f.is_del << " " << f.sec_cnt << "\n";
- return out;
- }
- std::istream& operator>> (std::istream &in, File &f) {
- in >> f.catalog;
- in >> f.name >> f.extension >> f.create_date >> f.create_time;
- in >> f.is_del >> f.sec_cnt;
- return in;
- }
- class Container {
- private:
- std::vector<File> data;
- public:
- void insert(const File &elem) {
- data.push_back(elem);
- }
- void change(const File &elem, const File &new_elem) {
- for (auto &i : data) {
- if (i == elem) {
- i = new_elem;
- }
- }
- }
- void del(const File &elem) {
- int pos = 0;
- for (auto &i : data) {
- if (i == elem) {
- break;
- }
- ++pos;
- }
- data.erase(data.begin() + pos);
- }
- bool find_catalog(std::string &cur_catalog) {
- for (auto &i : data) {
- if (cur_catalog == i.catalog) {
- return 1;
- }
- }
- return 0;
- }
- Container find_set_catalog(std::string &cur_catalog) {
- Container ans;
- for (auto &i : data) {
- if (cur_catalog == i.catalog) {
- ans.data.push_back(i);
- }
- }
- return ans;
- }
- bool find_catalog_binary(std::string &cur_catalog) {
- int l = 0;
- int r = data.size() - 1;
- if (r - l > 1) {
- while (r - l > 1) {
- int m = (r - l) / 2;
- if (data[m].catalog <= cur_catalog) {
- l = m;
- } else {
- r = m;
- }
- }
- return data[l].catalog == cur_catalog;
- } else {
- return cur_catalog == data[0].catalog;
- }
- return 0;
- }
- bool find_name(std::string &cur_name) {
- for (auto &i : data) {
- if (cur_name == i.name) {
- return 1;
- }
- }
- return 0;
- }
- Container find_set_name(std::string &cur_name) {
- Container ans;
- for (auto &i : data) {
- if (cur_name == i.name) {
- ans.data.push_back(i);
- }
- }
- return ans;
- }
- bool find_name_binary(std::string &cur_name) {
- int l = 0;
- int r = data.size() - 1;
- if (r - l > 1) {
- while (r - l > 1) {
- int m = (r - l) / 2;
- if (data[m].name <= cur_name) {
- l = m;
- } else {
- r = m;
- }
- }
- return data[l].name == cur_name;
- } else {
- return cur_name == data[0].name;
- }
- return 0;
- }
- bool find_date(std::string &cur_date) {
- for (auto &i : data) {
- if (cur_date == i.create_date) {
- return 1;
- }
- }
- return 0;
- }
- Container find_set_date(std::string &cur_date) {
- Container ans;
- for (auto &i : data) {
- if (cur_date == i.create_date) {
- ans.data.push_back(i);
- }
- }
- return ans;
- }
- bool find_date_binary(std::string &cur_date) {
- int l = 0;
- int r = data.size() - 1;
- if (r - l > 1) {
- while (r - l > 1) {
- int m = (r - l) / 2;
- if (data[m].create_date <= cur_date) {
- l = m;
- } else {
- r = m;
- }
- }
- return data[l].create_date == cur_date;
- } else {
- return cur_date == data[0].create_date;
- }
- return 0;
- }
- bool find_del(bool cur_del) {
- for (auto &i : data) {
- if (cur_del == i.is_del) {
- return 1;
- }
- }
- return 0;
- }
- Container find_set_del(bool cur_del) {
- Container ans;
- for (auto &i : data) {
- if (cur_del == i.is_del) {
- ans.data.push_back(i);
- }
- }
- return ans;
- }
- bool find_del_binary(bool cur_del) {
- int l = 0;
- int r = data.size() - 1;
- if (r - l > 1) {
- while (r - l > 1) {
- int m = (r - l) / 2;
- if (data[m].is_del <= cur_del) {
- l = m;
- } else {
- r = m;
- }
- }
- return data[l].is_del == cur_del;
- } else {
- return cur_del == data[0].is_del;
- }
- return 0;
- }
- friend std::ostream& operator<< (std::ostream &out, const Container &cont);
- };
- std::ostream& operator<< (std::ostream &out, const Container &cont) {
- for (auto i : cont.data) {
- out << i.catalog << "\n";
- out << i.name << " " << i.extension << " " << i.create_date << " " << i.create_time << "\n";
- out << i.is_del << " " << i.sec_cnt << "\n";
- }
- return out;
- }
- /*Container ReadFromFile(std::fstream& file) {
- file.seekg(0, ios::beg);
- Container result;
- while (file.peek() != EOF) {
- File f;
- file >> f.catalog << "\n";
- file >> f.name >> f.extension >> f.create_date >> f.create_time;
- file >> f.is_del >> f.sec_cnt;
- result.push_back(f);
- }
- file.close();
- return result;
- }*/
- int main() {
- int N;
- std::cin >> N;
- Container a;
- for (int i = 0; i < N; ++i) {
- int command;
- std::cin >> command;
- switch (command) {
- case 1: { // добавление
- File f;
- std::cin >> f;
- a.insert(f);
- }
- case 2: { // замена f на f2
- File f, f2;
- std::cin >> f >> f2;
- a.change(f, f2);
- }
- case 3: { // удаление f, если такой имеется
- File f;
- std::cin >> f;
- a.del(f);
- }
- case 4: { // вывод контейнера
- std::cout << a;
- std::cout << "\n";
- }
- case 5: { // поиск и выборка по каталогу
- std::string cur_catalog;
- std::cin >> cur_catalog;
- std::cout << a.find_catalog(cur_catalog) << "\n";
- std::cout << a.find_set_catalog(cur_catalog) << "\n";
- }
- case 6: { // поиск и выборка по имени
- std::string cur_name;
- std::cin >> cur_name;
- std::cout << a.find_catalog(cur_name) << "\n";
- std::cout << a.find_set_catalog(cur_name) << "\n";
- }
- case 7: { // поиск и выборка по дате
- std::string cur_date;
- std::cin >> cur_date;
- std::cout << a.find_date(cur_date) << "\n";
- std::cout << a.find_set_date(cur_date) << "\n";
- }
- case 8: { // поиск и выборка по признаку удаления
- std::string cur_del;
- std::cin >> cur_del;
- std::cout << a.find_date(cur_del) << "\n";
- std::cout << a.find_set_date(cur_del) << "\n";
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement