本文共 1899 字,大约阅读时间需要 6 分钟。
3 2ABCCDEEFGFABE0 0
great-grandparent-
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 17 18 using namespace std; 19 20 21 22 struct Node{ 23 char id; 24 int lch,rch; 25 }node[1000]; 26 27 int length=1; 28 29 30 int dep; 31 32 33 int findfa(int v1,int v2,int depp) 34 { 35 36 if(v1==0) 37 return 0; 38 39 if(v1==v2) 40 { 41 dep=depp; 42 return 1; 43 } 44 else 45 { 46 findfa(node[v1].lch,v2,depp+1); 47 findfa(node[v1].rch,v2,depp+1); 48 } 49 return 0; 50 } 51 52 53 54 55 56 int main() 57 { 58 59 60 int n,m; 61 62 int i,j,k; 63 64 while(scanf("%d%d",&n,&m)!=EOF) 65 { 66 if((n==0)&&(m==0)) 67 break; 68 69 getchar(); 70 71 for(i=1;i<=26;i++) 72 { 73 node[i].lch=node[i].rch=0; 74 } 75 76 77 78 int ans='A'-1; 79 for(i=0;i 2)134 {135 printf("great-");136 dep--;137 }138 139 printf("grandparent\n");140 }141 }142 }143 else144 {145 if(dep==1)146 {printf("child\n");}147 else if(dep==2)148 {149 printf("grandchild\n");150 }151 else152 {153 while(dep>2)154 {155 printf("great-");156 dep--;157 }158 159 printf("grandchild\n");160 }161 162 }163 }164 165 166 }167 168 169 170 171 172 173 174 175 176 return 0;177 }
转载于:https://www.cnblogs.com/zjushuiping/archive/2012/05/30/2526864.html