国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1035_找出直系親屬

2019-11-11 07:30:24
字體:
來源:轉載
供稿:網友
// 1035_找出直系親屬.cpp : 定義控制臺應用程序的入口點。//題目1035:找出直系親屬//時間限制:1 秒內存限制:32 兆特殊判題:否提交:2647解決:1054//題目描述://如果A,B是C的父母親,則A,B是C的parent,C是A,B的child,如果A,B是C的(外)祖父,祖母,則A,B是C的grandparent,C是A,B的grandchild,如果A,B是C的(外)曾祖父,曾祖母,則A,B是C的great-grandparent,C是A,B的great-grandchild,之后再多一輩,則在關系上加一個great-。//輸入://輸入包含多組測試用例,每組用例首先包含2個整數n(0<=n<=26)和m(0<m<50), 分別表示有n個親屬關系和m個問題, 然后接下來是n行的形式如ABC的字符串,表示A的父母親分別是B和C,如果A的父母親信息不全,則用-代替,例如A-C,再然后是m行形式如FA的字符串,表示詢問F和A的關系。//當n和m為0時結束輸入。//輸出://如果詢問的2個人是直系親屬,請按題目描述輸出2者的關系,如果沒有直系關系,請輸出-。//具體含義和輸出格式參見樣例.//樣例輸入://3 2//ABC//CDE//EFG//FA//BE//0 0//樣例輸出://great-grandparent//-//來源://2009年浙江大學計算機及軟件工程研究生機試真題#include "stdafx.h"#include "stdio.h"#include "iostream"#include "string.h"#include "string"using namespace std;int arr[1000];void find(int a,int b){ int flag = 0; if(!flag){ int count = 0; int temp_a = a; while(arr[temp_a]!=-1){ count++; if(arr[temp_a]!=b){ temp_a = arr[temp_a]; } else{ if(count>1){ for(int i = 2;i<count;i++) cout<<"great-"; cout<<"grandparent"<<endl; } else cout<<"parent"<<endl; flag = 1; break; } } } if(!flag){ int count = 0; int temp_b = b; while(arr[temp_b]!=-1){ count++; if(arr[temp_b]!=a){ temp_b = arr[temp_b]; } else{ if(count>1){ for(int i = 2;i<count;i++) cout<<"great-"; cout<<"grandchild"<<endl; } else cout<<"child"<<endl; flag = 1; break; } } } if(!flag) cout<<"-"<<endl;}int main(){ int n,m; while(cin>>n>>m && (m||n)){ string a; memset(arr,-1,sizeof(arr)); while(n--){ cin>>a; if(a[1]!='-') arr[a[1]-'A'] = a[0]-'A'; if(a[2]!='-') arr[a[2]-'A'] = a[0]-'A'; } while(m--){ cin>>a; find(a[0]-'A',a[1]-'A'); } } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 台中市| 济源市| 长顺县| 县级市| 大方县| 凉城县| 广汉市| 安陆市| 东光县| 会理县| 嘉义县| 灵璧县| 英吉沙县| 陆河县| 绍兴市| 平谷区| 昭觉县| 颍上县| 阿荣旗| 神池县| 吉隆县| 海伦市| 钦州市| 澄迈县| 蒙自县| 保定市| 辽中县| 岫岩| 时尚| 米脂县| 东方市| 北安市| 渭源县| 团风县| 弋阳县| 贵溪市| 甘南县| 湘西| 扎鲁特旗| 扎鲁特旗| 若羌县|