CodeForces Gym 100989J Objects Panel (A)

水题,文件夹的展开折叠操作,是一个树,递归输出就行,数据应该是有点小问题,可能会出现 + 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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值