Skip to main content

Zoho Interview | Set 1 Question 5

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..

 

My solution ::

#include <iostream>
#include<cstdlib>
using namespace std;
int count=0;
string a[4][2]={
   {"luke", "shaw"},
   {"wayne", "rooney"},
   {"rooney", "ronaldo"},
   {"shaw", "rooney"}
 };
void grandchi(string x){
  for(int i=0;i<4;i++){
 if(x==a[i][1]){
  count++;
 }
  } 
}
int main() {
 string s,s1;
  
 for(int i=0;i<4;i++){
  for(int j=0;j<2;j++){
   cout<<a[i][j]<<"\n";
  }
  
 }
 cout<<"enter string"<<"\n";
 cin>>s;
 cout<<s;
 for(int i=0;i<4;i++){
  if(s==a[i][1]){
   s1=a[i][0];
   grandchi(s1);
  }
 }
 cout<<"grand children:"<<count;
 return 0;
}

 

Comments

  1. Hi, in line 5, is "string" a data type in C++? I tried running on Borland C++ and it shows error.
    Also, what is the use of "using namespace std" ?

    Thanks in advance !!!

    ReplyDelete
    Replies
    1. When you use "using namespace std" Then you don't need to scope resolute every c++ object you are using in your program like std::

      If you still have a doubt refer this link:https://www.quora.com/What-does-using-namespace-std-mean-in-C++

      Delete

Post a Comment

Popular posts from this blog

ORACLE 9i practice solutions

Created by BCL easyConverter SDK 3 (HTML Version)

Zoho Puzzle Questions With Answers

Measuring Time Logic Puzzle You are given with two ropes with variable width. However if we start burning both the ropes, they will burn at exactly same time i.e. an hour. The ropes are non-homogeneous in nature. You are asked to measure 45 minutes by using these two ropes.

How can you do it?

Please note that you can’t break the rope in half as it is being clearly stated that the ropes are non-homogeneous in nature.
Answer & Explanation Solution: 45 minutes

Explanation :
All you have to do is burn the first rope from both the ends and the second rope from one end only simultaneously. The first rope will burn in 30 minutes (half of an hour since we burned from both sides) while the other rope would have burnt half. At this moment, light the second rope from the other end as well. Where, the second rope would have taken half an hour more to burn completely, it will take just 15 minutes as we have lit it from the other end too.

Thus you have successfully calculated 30+15 = 45 minutes …

Hackerrank > SQL > Basic Select

Select
01-Select All
Given a City table, whose fields are described as +-------------+----------+ | Field       | Type     | +-------------+----------+ | ID          | int(11)  | | Name        | char(35) | | CountryCode | char(3)  | | District    | char(20) | | Population  | int(11)  | +-------------+----------+
write a query that will fetch all columns for every row in the table.

My Solution
SELECT*FROM city;
---------------------------------------------------------------------------------
02-Select by ID
Given a City table, whose fields are described as