Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- int n;
- scanf ("%d",&n);
- n--;
- int* key = new int[n];
- int* door = new int[n];
- for(int i = 0; i < n; i++) scanf ("%d",&key[i]);
- int ans = 0;
- unordered_map<int, int> inventory;
- for(int i = 0; i < n; i++){
- int temp;
- scanf ("%d",&temp);
- inventory[key[i]]++;
- if(inventory[temp] == 0) ans++;
- else inventory[temp]--;
- }
- cout << ans;
- return 0;
- }
- //3
- class Directory{
- public:
- string name;
- Directory* parent;
- map<string, Directory*> child;
- Directory(Directory* par, string _name): parent(par), name(_name){};
- bool operator<(const Directory& other) const{
- return this->name < other.name;
- }
- bool hasDir(string dirName){
- if(child.find(dirName) != child.end()) return true;
- return false;
- }
- void mkdir(string dirName){
- if(this->hasDir(dirName)) cout << "Directory already exists\n";
- else{
- Directory* temp = new Directory(this, dirName);
- child[dirName] = temp;
- }
- }
- void ls(){
- for (auto dir : child) cout << dir.first << ' ';
- cout << '\n';
- }
- Directory* cd(string dirName){
- if (dirName == ".." && this->parent) return this->parent;
- else if(this->hasDir(dirName)) return child[dirName];
- else{
- cout << "No such directory\n";
- return this;
- }
- }
- string pwd(){
- string container;
- if(this->parent != NULL) container += this->parent->pwd();
- container += this->name;
- container += "/";
- return container;
- }
- };
- int main() {
- int n;
- cin >> n;
- Directory* current = new Directory(NULL, "");
- for(int i = 0; i < n; i++){
- string op;
- cin >> op;
- if(op == "mkdir"){
- string arg;
- cin >> arg;
- current->mkdir(arg);
- }
- else if(op == "ls"){
- current->ls();
- }
- else if(op == "cd"){
- string arg;
- cin >> arg;
- current = current->cd(arg);
- }
- else if(op == "pwd"){
- cout << current->pwd() << '\n';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement