西工大数据结构极简解法--014求广义表深度

题目描述

在这里插入图片描述

极简解法

#include<stdio.h>
#include<string.h>
int main()
{
	int depth=0,maxn=0;
	char s[10000];
	gets(s);
	for(int i=0;i<strlen(s);i++)
	{
		if(s[i]=='(')
		{
			depth++;
			if(maxn<depth)maxn=depth;
		}
		if(s[i]==')')depth--;
	}
	printf("%d\n",maxn);
	printf("%d",maxn);
	return 0;
}

·

猜你喜欢

转载自blog.csdn.net/weixin_45619006/article/details/107292504