Given a two dimensional array of string like
<”luke”, “shaw”> <”wayne”, “rooney”> <”rooney”, “ronaldo”> <”shaw”, “rooney”>
Where the first string is “child”, second string is “Father”. And given “ronaldo” we have to find his no of grandchildren Here “ronaldo” has 2 grandchildren. So our output should be 2.
SOLUTION
using System;
public class Test
{
public static void Main()
{
var noOfInputs = Console.ReadLine();
int noOfInputLines = Convert.ToInt32(noOfInputs);
string[,] FatherSonArray= new String[noOfInputLines,noOfInputLines];
for(int father=0;father<noOfInputLines;father++)
{
for(int son=0;son<2;son++)
{
FatherSonArray[father,son] = Console.ReadLine();
}
}
Console.WriteLine("No of grandchildrens:");
string GrandFather = Console.ReadLine();
int NoOfGrandSons=0;
Console.WriteLine(GrandFather);
string GrandFatherSon=" ";
for(int father=0;father<noOfInputLines;father++)
{
if(FatherSonArray[father,1]==GrandFather)
{
GrandFatherSon=FatherSonArray[father,0];
}
}
for(int father=0;father<noOfInputLines;father++)
{
if(FatherSonArray[father,1]==GrandFatherSon)
{
NoOfGrandSons++;
}
}
Console.WriteLine(NoOfGrandSons);
}
}
Comments
Post a Comment