1050: Find the immediate family

Source: Internet
Author: User

1050: Find out immediate family time limit: 1 Sec memory limit: MB
Submitted by: 321 Resolution: 264
Submitted State [Discussion Version] Title Description If a, B is the parent of C, then a A, a, B is the parent,c of C is a A, a A, if A is C (outside) grandfather, grandmother, then a B is the grandparent,c of C is a A, B is the grandchild, if A is C (outside) great grandfather, Once grandmother, then A, B is the great-grandparent,c of C is a, b great-grandchild, then more than one generation, then add a great-on the relationship. The input input contains multiple sets of test cases, each of which consists of 2 integers n (0<=n<=26) and M (0&LT;M&LT;50), each representing n kinship and M questions, followed by a string of n rows, such as ABC, which indicates that A's parents are B and C, respectively. If A's parental information is incomplete, then use-instead, for example A-c, then the M-line form of the FA string, which indicates the relationship between F and a.
When N and m are 0 o'clock end input. Output if the 2 persons questioned are immediate family members, please describe the relationship of output 2 according to the topic, if there is no direct relationship, please output-.
Refer to the example for the specific meaning and output format. Sample input
3 2ABCCDEEFGFABE0 0
Sample output
great-grandparent-


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace Std;
Char cmp (char A,char b) {
Return a<b?0:1;
}
int main () {
int m,n;
while (cin>>m>>n&& (m!=0&&n!=0)) {
String Str[m];
for (int i=0;i<m;i++) {
cin>>str[i];
}
Char wt[n][2];
for (int i=0;i<n;i++) {
for (int j=0;j<2;j++) {
cin>>wt[i][j];
}
}
for (int i=0;i<n;i++) {
int temp=0,index=0;
int j=m-1;
int count=0;
if (Wt[i][1]<wt[i][0]) {index=1;};
Sort (wt[i],wt[i]+2,cmp);
while (j>=0) {
if (Str[j].find (wt[i][0])!=string::npos) {
count++;
WT[I][0]=STR[J][0];
}
if (Wt[i][1]==str[j][0]) {temp=j;break;}
j--;
}
if (wt[i][1]!=str[temp][0]) count=0;
if (index==1) {
while (COUNT&GT;2) {
cout<< "great-";
count--;
}
if (count==2)
cout<< "Grandparent" <<endl;
if (count==1)
cout<< "Parent" <<endl;
if (count==0)
cout<< "-" <<endl;
}
else{
while (COUNT&GT;2) {
cout<< "great-";
count--;
}
if (count==2)
cout<< "grandchild" <<endl;
if (count==1)
cout<< "Child" <<endl;
if (count==0)
cout<< "-" <<endl;
}
}
}
return 0;
}

1050: Find the immediate family

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.