-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC++.cpp
72 lines (66 loc) · 1.24 KB
/
C++.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int countDot(string s)
{
for (int i = 0; i < s.size(); i++)
{
if (s[i] != '.')
{
return i;
}
}
return s.size();
}
string getNoDot(string s)
{
string _s = "";
for (int i = 0; i < s.size(); i++)
{
if (s[i] != '.')
{
_s += s[i];
}
}
return _s;
}
string vectorToString(vector<string> v)
{
string s = "";
for (int i = 0; i < v.size(); i++)
{
s += v[i];
if (i != v.size() - 1)
{
s += " > ";
}
}
return s;
}
int main()
{
int count;
cin >> count;
cin.ignore();
int currentDepth = 0;
vector<string> current;
for (int i = 0; i < count; i++)
{
string line;
getline(cin, line);
int depth = countDot(line);
if (currentDepth != depth)
{
cout << vectorToString(current) << "\n";
for (; currentDepth > depth; currentDepth--)
{
current.pop_back();
}
}
current.push_back(getNoDot(line));
currentDepth++;
}
cout << vectorToString(current) << "\n";
}