-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
35 lines (33 loc) · 877 Bytes
/
program.cpp
File metadata and controls
35 lines (33 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "../include/pre.h"
string simplifyPath(string path)
{
std::vector<string> real;
std::stringstream ss(path);
while (!ss.eof())
{
while ('/' == ss.peek()) ss.get();
std::stringstream oss;
while ('/' != ss.peek() && std::char_traits<char>::eof() != ss.peek()) oss << static_cast<char>(ss.get());
auto node = oss.str();
for (int i : node) cout << i << ", ";
if ("" == node) continue;
if ("." == node) continue;
if (".." == node)
{
if (!real.empty()) real.pop_back();
continue;
}
real.push_back(node);
cout << node << endl;
}
if (real.empty()) return "/";
std::stringstream oss;
for (auto& node : real)
oss << '/' << node;
return oss.str();
}
int main()
{
cout << simplifyPath("//..");
return 0;
}