📄 3031707_ac_0ms_228k.cpp
字号:
#include <stdio.h>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
stack <int> file;
vector <string> dir[10];
const string str = "| ";
void print(int n,string tmp)
{
for(int i = 0; i < n; i++)
{
cout << str;
}
cout << tmp << endl;
}
bool cmp(string a,string b)
{
return a < b;
}
void output(int n,int p)
{
sort(dir[p].begin(),dir[p].end(),cmp);
for(int i = 0; i < dir[p].size(); i++)
{
for(int j = 0; j < n; j++)
{
cout << str;
}
cout << dir[p][i] << endl;
}
}
int main()
{
int i, cas (1), n, p;
string tmp;
while(true)
{
cin >> tmp;
n = 0;
if(tmp=="#")
{
break;
}
cout << "DATA SET " << cas++ << ":" << endl;
cout << "ROOT" << endl;
file.push(0);
if(tmp=="*")
{
cout << endl;
continue;
}
p = file.top();
if(tmp.at(0)=='f')
{
dir[p].push_back(tmp);
}
if(tmp.at(0)=='d')
{
n++;
file.push(n);
print(n,tmp);
}
while(true)
{
cin >> tmp;
if(tmp=="*")
{
p = file.top();
file.pop();
output(n,p);
dir[p].clear();
n--;
break;
}
if(tmp=="]")
{
p = file.top();
file.pop();
output(n,p);
dir[p].clear();
n--;
continue;
}
if(tmp.at(0)=='f')
{
p = file.top();
dir[p].push_back(tmp);
}
else
{
n++;
file.push(n);
print(n,tmp);
}
}
cout << endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -