C#就是好玩,用pascal用惯了用这个简直舒服死,vs.net和turbo pascal肯定不是一个级别的.pascal不面向对象,弄得我们想做棵树都得定record然后放在数组里面,c#可以直接指向,而且本身就是一个对象..不需要用什么怪异的数组存...速度么,没仔细测,不过都是瞬解.呵呵.偶的第一个程序是helloworld,这个么,是第一个像样的程序...
嗯,不废话咯
FBI 树
** (fbi.pas/dpr/c/cpp) **
【问题描述】
我们可以把由“ 0 ”和“ 1 ”组成的字符串分为三类:全“ 0 ”串称为 B 串,全“ 1 ”串称为 I 串,既含“ 0 ”又含“ 1 ”的串则称为 F 串。
FBI 树是一种二叉树 [1] ,它的结点类型也包括 F 结点, B 结点和 I 结点三种。由一个长度为 2 N 的“ 01 ”串 S 可以构造出一棵 FBI 树 T ,递归的构造方法如下:
T 的根结点为 R ,其类型与串 S 的类型相同;
若串 S 的长度大于 1 ,将串 S 从中间分开,分为等长的左右子串 S1 和 S2 ;由左子串 S1 构造 R 的左子树 T1 ,由右子串 S2 构造 R 的右子树 T2 。
现在给定一个长度为 2 N 的“ 01 ”串,请用上述构造方法构造出一棵 FBI 树,并输出它的后序遍历 [2] 序列。
【输入文件】
输入文件 ** fbi.in ** 的第一行是一个整数 N ( 0 <= N <= 10 ),第二行是一个长度为 2 N 的“ 01 ”串。
【输出文件】
输出文件 ** fbi.out ** 包括一行,这一行只包含一个字符串,即 FBI 树的后序遍历序列。
【样例输入】
3
10001011
【样例输出】
IBFBBBFIBFIIIFF
【数据规模】
对于 40% 的数据, N <= 2 ;
对于全部的数据, N <= 10 。 
[1] 二叉树:二叉树是结点的有限集合,这个集合或为空集,或由一个根结点和两棵不相交的二叉树组成。这两棵不相交的二叉树分别称为这个根结点的左子树和右子树。
[2] 后序遍历:后序遍历是深度优先遍历二叉树的一种方法,它的递归定义是:先后序遍历左子树,再后序遍历右子树,最后访问根。
using System;
namespace FBI
{
///
1<summary>
2/// Class1 的摘要说明。
3/// </summary>
public class tree
{
public char data=new char();
public tree lc=null,rc=null;
public tree(string s)
{
this.data=mydata(s);
if(s.Length!=1)
{
this.lc=mychild(s.Substring(0,s.Length/2));
this.rc=mychild(s.Substring(s.Length/2,s.Length/2));
}
}
private char mydata(string s)
{
char ch=s[0];
for (int i=0;i
1<s.length;i++) !="null){this.rc.show();}" 'b';}="" 'f';}="" 'i';}="" )="" <summary="" class="" class1="" console.write(this.data);="" else="" if(ch="0" if(s[i]!="ch){return" if(this.lc="" if(this.rc="" mychild(string="" mytree="new" mytree.mydata(s);="" mytree;="" private="" public="" return="" s)="" show()="" tree="" tree(s);="" void="" {="" {return="" }="">
2/// 应用程序的主入口点。
3///
4[STAThread]
5static int sqr(int a)
6{
7int c=new int();
8c=1;
9for (int i=0;i<a;i++)
10{
11c=2*c;
12}
13return c;
14}
15static void Main(string[] args)
16{
17string s;
18int n=0;
19//n = System.Convert.ToInt32(System.Console.ReadLine());
20//s = System.Convert.ToString(System.Console.ReadLine());
21n=3;
22s="10001011";
23Console.WriteLine(sqr(n));//感觉N没用,当然是不给非法参数的时候
24tree mytree=new tree(s);
25mytree.show();
26Console.ReadLine();
27//
28// TODO: 在此处添加代码以启动应用程序
29//
30}
31}
32}
33
34
35---</s.length;i++)>