标签:bsp line 格式 amp 信息 %s class ros 结束
3 2 ABC CDE EFG FA BE 0 0
great-grandparent -
#include<stdio.h> #define INF 1000000000 int map[105][105]; void Floyd() { for(int k = 1 ;k <= 100 ;k ++) for(int i = 1 ;i <= 100 ;i ++) for(int j = 1 ;j <= 100 ;j ++) if(map[i][j] > map[i][k] + map[k][j]) map[i][j] = map[i][k] + map[k][j]; } int minn(int x, int y) { return x < y ? x : y; } int main () { int n ,m ,i ,j ,a ,b ,c; char str[10]; while(scanf("%d %d" ,&n ,&m) && n + m) { for(i = 1 ;i <= 100 ;i ++) for(j = 1 ;j <= 100 ;j ++) if(i == j)map[i][j] = 0; else map[i][j] = INF; for(i = 1 ;i <= n ;i ++) { scanf("%s" ,str); a = str[0]; b = str[1]; c = str[2]; map[a][b] = map[a][c] = 1; } Floyd(); for(i = 1 ;i <= m ;i ++) { scanf("%s" ,str); a = str[0]; b = str[1]; c = minn(map[a][b] ,map[b][a]); if(c == INF || !c) { puts("-"); continue; } if(c == 1) { if(map[a][b] == 1) puts("child"); else puts("parent"); } else { if(map[a][b] != INF) { c -= 2; for(j = 1 ;j <= c ;j ++) printf("great-"); puts("grandchild"); } else { c -= 2; for(j = 1 ;j <= c ;j ++) printf("great-"); puts("grandparent"); } } } } return 0; }
标签:bsp line 格式 amp 信息 %s class ros 结束
原文地址:https://www.cnblogs.com/bernieloveslife/p/9736583.html