20240109
This commit is contained in:
115
1335.cpp
Normal file
115
1335.cpp
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
class ClassType {
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum ImportType {
|
||||||
|
kPublicImport, kProtectedImport, kPrivateImport
|
||||||
|
};
|
||||||
|
enum StatusType {
|
||||||
|
kPublic = 4, kProtected = 3, kPrivate = 2, kUnvisible = 1, kNone = 0
|
||||||
|
};
|
||||||
|
void Import(ClassType &src, ImportType import_type) {
|
||||||
|
if (import_type == ImportType::kPublicImport) {
|
||||||
|
pub_anc.push_back(&src);
|
||||||
|
} else if (import_type == ImportType::kProtectedImport) {
|
||||||
|
prot_anc.push_back(&src);
|
||||||
|
} else {
|
||||||
|
priv_anc.push_back(&src);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddElement(const std::string &name, StatusType status) {
|
||||||
|
elements[name] = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusType QueryElement(const std::string &name) {
|
||||||
|
return DFSSearch(this, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static StatusType DFSSearch(ClassType *rt, const std::string name) {
|
||||||
|
StatusType res = StatusType::kNone;
|
||||||
|
if (rt->elements.find(name) != rt->elements.end()) res = rt->elements[name];
|
||||||
|
for (int i = 0; i < rt->pub_anc.size(); i++) {
|
||||||
|
StatusType sub_res = DFSSearch(rt->pub_anc[i], name);
|
||||||
|
if (sub_res == StatusType::kPrivate) sub_res = StatusType::kUnvisible;
|
||||||
|
res = (sub_res > res) ? sub_res : res;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < rt->prot_anc.size(); i++) {
|
||||||
|
StatusType sub_res = DFSSearch(rt->prot_anc[i], name);
|
||||||
|
if (sub_res == StatusType::kPrivate) sub_res = StatusType::kUnvisible;
|
||||||
|
if ((sub_res == StatusType::kPublic) ||
|
||||||
|
(sub_res == StatusType::kProtected)) sub_res = StatusType::kProtected;
|
||||||
|
res = (sub_res > res) ? sub_res : res;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < rt->priv_anc.size(); i++) {
|
||||||
|
StatusType sub_res = DFSSearch(rt->priv_anc[i], name);
|
||||||
|
if (sub_res == StatusType::kPrivate) sub_res = StatusType::kUnvisible;
|
||||||
|
if ((sub_res == StatusType::kPublic) ||
|
||||||
|
(sub_res == StatusType::kProtected)) sub_res = StatusType::kPrivate;
|
||||||
|
res = (sub_res > res) ? sub_res : res;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unordered_map<std::string, StatusType>elements;
|
||||||
|
std::vector<ClassType *>pub_anc, prot_anc, priv_anc;
|
||||||
|
};
|
||||||
|
int main() {
|
||||||
|
#ifdef local
|
||||||
|
freopen("pro.in", "r", stdin);
|
||||||
|
#endif // ifdef local
|
||||||
|
int n;
|
||||||
|
std::unordered_map<std::string, ClassType> class_registery;
|
||||||
|
std::cin >> n;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
std::string name;
|
||||||
|
std::cin >> name;
|
||||||
|
class_registery[name];
|
||||||
|
int k0; std::cin >> k0;
|
||||||
|
for (int j = 0; j < k0; j++) {
|
||||||
|
std::string method, srcname;
|
||||||
|
std::cin >> method >> srcname;
|
||||||
|
if (method == "public") class_registery[name].Import(
|
||||||
|
class_registery[srcname],
|
||||||
|
ClassType::ImportType::kPublicImport);
|
||||||
|
else if (method == "private") class_registery[name].Import(
|
||||||
|
class_registery[srcname],
|
||||||
|
ClassType::ImportType::kPrivateImport);
|
||||||
|
else class_registery[name].Import(
|
||||||
|
class_registery[srcname],
|
||||||
|
ClassType::ImportType::kProtectedImport);
|
||||||
|
}
|
||||||
|
int k1; std::cin >> k1;
|
||||||
|
for (int j = 0; j < k1; j++) {
|
||||||
|
std::string mode, element_name;
|
||||||
|
std::cin >> mode >> element_name;
|
||||||
|
if (mode == "public") class_registery[name].AddElement(element_name,
|
||||||
|
ClassType::StatusType::kPublic);
|
||||||
|
else if (mode == "private") class_registery[name].AddElement(element_name,
|
||||||
|
ClassType::StatusType::kPrivate);
|
||||||
|
else class_registery[name].AddElement(element_name,
|
||||||
|
ClassType::StatusType::kProtected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int m;
|
||||||
|
std::cin >> m;
|
||||||
|
for (int i = 0; i < m; i++) {
|
||||||
|
std::string class_name, element_name;
|
||||||
|
std::cin >> class_name >> element_name;
|
||||||
|
ClassType::StatusType stat = class_registery[class_name].QueryElement(
|
||||||
|
element_name);
|
||||||
|
switch (stat) {
|
||||||
|
case ClassType::StatusType::kNone: std::cout << "None\n"; break;
|
||||||
|
case ClassType::StatusType::kPrivate: std::cout << "Private\n"; break;
|
||||||
|
case ClassType::StatusType::kProtected: std::cout << "Protected\n"; break;
|
||||||
|
case ClassType::StatusType::kPublic: std::cout << "Public\n"; break;
|
||||||
|
case ClassType::StatusType::kUnvisible: std::cout << "Can not Fetch\n"; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
88
1427.hpp
Normal file
88
1427.hpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#ifndef PYLIST_H
|
||||||
|
#define PYLIST_H
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <memory>
|
||||||
|
#include <queue>
|
||||||
|
class pylist;
|
||||||
|
std::queue<std::shared_ptr<std::vector<pylist *> > > bucket_keeper;
|
||||||
|
std::queue<std::shared_ptr<pylist> > pylist_keeper;
|
||||||
|
class pylist {
|
||||||
|
private:
|
||||||
|
|
||||||
|
bool is_list;
|
||||||
|
int int_val;
|
||||||
|
std::vector<pylist *> *children_ptr;
|
||||||
|
static void Print(
|
||||||
|
std::ostream &os,
|
||||||
|
const pylist &ls,
|
||||||
|
std::unordered_set<std::vector<pylist *> *>st) {
|
||||||
|
os << '[';
|
||||||
|
if (st.find(ls.children_ptr) != st.end()) {
|
||||||
|
os << "...]";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
st.insert(ls.children_ptr);
|
||||||
|
for (int i = 0; i < ls.children_ptr->size(); i++) {
|
||||||
|
if (i > 0) os << ", ";
|
||||||
|
if (((*ls.children_ptr)[i])->is_list)
|
||||||
|
Print(os, *((*ls.children_ptr)[i]), st);
|
||||||
|
else os << ((*ls.children_ptr)[i])->int_val;
|
||||||
|
}
|
||||||
|
os << ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// ~pylist() {}
|
||||||
|
|
||||||
|
pylist() {
|
||||||
|
is_list = true;
|
||||||
|
std::vector<pylist *> *ptr = new std::vector<pylist *>();
|
||||||
|
children_ptr = ptr;
|
||||||
|
bucket_keeper.emplace(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
pylist(int v) {
|
||||||
|
is_list = false;
|
||||||
|
int_val = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pylist(const pylist &x) {}
|
||||||
|
|
||||||
|
// pylist& operator=(const pylist &x) {
|
||||||
|
// return *this;
|
||||||
|
// }
|
||||||
|
|
||||||
|
void append(const pylist &x) {
|
||||||
|
pylist *ptr = new pylist(x);
|
||||||
|
children_ptr->emplace_back(ptr);
|
||||||
|
pylist_keeper.emplace(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
pylist pop() {
|
||||||
|
pylist tmp = *((*(children_ptr))[children_ptr->size() - 1]);
|
||||||
|
children_ptr->pop_back();
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
pylist& operator[](size_t i) {
|
||||||
|
return *((*(children_ptr))[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream &os, const pylist &ls) {
|
||||||
|
std::unordered_set<std::vector<pylist *> *>
|
||||||
|
st;
|
||||||
|
if (ls.is_list)
|
||||||
|
Print(os, ls, st);
|
||||||
|
else os << ls.int_val;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator int() const { return int_val; }
|
||||||
|
};
|
||||||
|
#endif // PYLIST_H
|
Reference in New Issue
Block a user