-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (54 loc) · 1.21 KB
/
Copy pathmain.cpp
File metadata and controls
56 lines (54 loc) · 1.21 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Created by Zlata Kovrigina on 11/27/25.
//
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
int main() {
std::string input;
getline(std::cin, input);
std::stringstream ss(input);
std::string split;
std::vector<std::string> paths;
int pop = 0;
while (getline(ss, split, '/')) {
if (split == "" || split == ".") {
continue;
}
bool allDot = true;
int dots = 0;
for (char c : split) {
if (c == '.') {
dots++;
}
if (c != '.') {
allDot = false;
}
}
if (allDot) {
pop = dots - 1;
while (pop > 0 && !paths.empty()) {
paths.pop_back();
pop--;
}
continue;
}
paths.push_back(split);
}
if (paths.empty()) {
std::cout << "/" << std::endl;
}
else {
std::cout << "/";
for (int i = 0; i < paths.size(); i++) {
std::cout << paths[i];
if (i + 1 < paths.size()) {
std::cout << "/";
}
}
std::cout << std::endl;
}
return 0;
}
#include "main.h"