解题思路:采用结构体来存储家谱
其中需要注意的是祖先和后代的判断
#include <stdio.h> #include <string.h> typedef char Element[11]; typedef struct { Element Name; int parent; int space; } Genealogy; Genealogy G[100]; int n,m; void Initial(); int GetWord(Element word); int FindPos(Element x); int JudgeChild(int x,int y); int JudgeParent(int x,int y); int JudgeSibling(int x,int y) ; int JudgeDescendant(int x,int y); int JudgeAncestor(int x,int y); void Judge(); int main(int argc,char **argv) { Initial(); Judge(); return 0; } int GetWord(Element word) { char c; int p=0; int space=0; scanf("%c",&c); while(!isalpha(c)&&c!=' ') scanf("%c",&c); while(c==' ') { space++; scanf("%c",&c); } while(isalpha(c)) { word[p++]=c; scanf("%c",&c); } if(c==' ') { word[p]='