水题,文件夹的展开折叠操作,是一个树,递归输出就行,数据应该是有点小问题,可能会出现 + 0,这样的情况,所以先判0再判+-
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <vector>
using namespace std;
#define ll long long
int child[102][102];
int N;
bool expanded[102];
int readint()
{
int tmp = 0;
char ch;
bool read = false;
while (ch = getchar())
{
if (ch >= '0'&&ch <= '9')
{
read = true;
tmp = tmp * 10 + ch - '0';
}
else if (read)
{
break;
}
else
{
continue;
}
}
return tmp;
}
char readchar()
{
char ch;
while (ch = getchar())
{
if (ch == '-' || ch == '+')
{
break;
}
}
return ch;
}
void print(int pos, int depth)
{
for (int i = 0; i < depth; ++i)
printf(" ");
if (child[pos][0] == 0)
printf(" object%d\n", pos);
else
{
if (expanded[pos])
{
printf("- object%d\n", pos);
for (int i = 1; i <= child[pos][0]; ++i)
{
print(child[pos][i], depth + 1);
}
}
else
printf("+ object%d\n", pos);
}
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
N = readint();
char ch;
for (int i = 0; i <= N; ++i)
{
ch = readchar();
if (ch == '-')
expanded[i] = true;
else
expanded[i] = false;
child[i][0] = readint();
for (int j = 1; j <= child[i][0]; ++j)
{
child[i][j] = readint();
}
}
if (expanded[0])
{
if (child[0][0] == 0)
printf(" project\n");
else
{
printf("- project\n");
for (int i = 1; i <= child[0][0]; ++i)
{
print(child[0][i], 1);
}
}
}
else
{
printf("+ project\n");
}
//system("pause");
//while (1);
/*
- project
- object2
object6
object5
+ object1
*/
return 0;
}