Guest User

Untitled

a guest
Dec 14th, 2019
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int main() {
  2. int n;
  3. scanf ("%d",&n);
  4. n--;
  5.  
  6. int* key = new int[n];
  7. int* door = new int[n];
  8.  
  9. for(int i = 0; i < n; i++) scanf ("%d",&key[i]);
  10.  
  11. int ans = 0;
  12. unordered_map<int, int> inventory;
  13.  
  14. for(int i = 0; i < n; i++){
  15. int temp;
  16. scanf ("%d",&temp);
  17. inventory[key[i]]++;
  18. if(inventory[temp] == 0) ans++;
  19. else inventory[temp]--;
  20. }
  21.  
  22. cout << ans;
  23.  
  24. return 0;
  25. }
  26.  
  27.  
  28. //3
  29. class Directory{
  30. public:
  31. string name;
  32. Directory* parent;
  33. map<string, Directory*> child;
  34.  
  35. Directory(Directory* par, string _name): parent(par), name(_name){};
  36.  
  37. bool operator<(const Directory& other) const{
  38. return this->name < other.name;
  39. }
  40.  
  41. bool hasDir(string dirName){
  42. if(child.find(dirName) != child.end()) return true;
  43. return false;
  44. }
  45.  
  46. void mkdir(string dirName){
  47. if(this->hasDir(dirName)) cout << "Directory already exists\n";
  48. else{
  49. Directory* temp = new Directory(this, dirName);
  50. child[dirName] = temp;
  51. }
  52. }
  53.  
  54. void ls(){
  55. for (auto dir : child) cout << dir.first << ' ';
  56. cout << '\n';
  57. }
  58.  
  59. Directory* cd(string dirName){
  60. if (dirName == ".." && this->parent) return this->parent;
  61. else if(this->hasDir(dirName)) return child[dirName];
  62. else{
  63. cout << "No such directory\n";
  64. return this;
  65. }
  66. }
  67.  
  68. string pwd(){
  69. string container;
  70. if(this->parent != NULL) container += this->parent->pwd();
  71. container += this->name;
  72. container += "/";
  73. return container;
  74. }
  75. };
  76.  
  77. int main() {
  78. int n;
  79. cin >> n;
  80.  
  81. Directory* current = new Directory(NULL, "");
  82.  
  83. for(int i = 0; i < n; i++){
  84. string op;
  85. cin >> op;
  86. if(op == "mkdir"){
  87. string arg;
  88. cin >> arg;
  89. current->mkdir(arg);
  90. }
  91. else if(op == "ls"){
  92. current->ls();
  93. }
  94. else if(op == "cd"){
  95. string arg;
  96. cin >> arg;
  97. current = current->cd(arg);
  98. }
  99. else if(op == "pwd"){
  100. cout << current->pwd() << '\n';
  101. }
  102. }
  103.  
  104. return 0;
  105. }
RAW Paste Data