count the character in string

Problem Statement
Given a string ,Write a program to print letter followed by it’s frequency.
Input Format
input must be in string
Output Format
count the characters.. and print the alphabet and its count adjacently
Sample Input
aaabcc
Sample Output
a3b1c2

My Code:


#include <iostream>
#include<string.h>
using namespace std;


int main(void) {
    int hash[26]={0};
    char a[100];
    cin>>a;
   
    for(int i=0;i<strlen(a);i++)
    {
        hash[a[i]-97]++;
    }
   
    for(int i=0;i<26;i++)
    {
        if(hash[i]>=1)
        {
            char x=i+97;
            cout<<x<<hash[i];
        }
      
        }
   
    return 0;
}

Call Taxi Booking Application program - zoho interview question

 Design a Call taxi booking application
-There are n number of taxi’s. For simplicity, assume 4. But it should work for any number of taxi’s.
-The are 6 points(A,B,C,D,E,F)
-All the points are in a straight line, and each point is 15kms away from the adjacent points.
-It takes 60 mins to travel from one point to another
-Each taxi charges Rs.100 minimum for the first 5 kilometers and Rs.10 for the subsequent kilometers.
-For simplicity, time can be entered as absolute time. Eg: 9hrs, 15hrs etc.
-All taxi’s are initially stationed at A.
-When a customer books a Taxi, a free taxi at that point is allocated
-If no free taxi is available at that point, a free taxi at the nearest point is allocated.
-If two taxi’s are free at the same point, one with lower earning is allocated
-Note that the taxi only charges the customer from the pickup point to the drop point. Not the distance it travels from an adjacent point to pickup the customer.
-If no taxi is free at that time, booking is rejected
Design modules for
1)    Call taxi booking 
Input 1:
Customer ID: 1
Pickup Point: A
Drop Point: B
Pickup Time: 9

Output 1:
Taxi can be allotted.
Taxi-1 is allotted

Input 2:
Customer ID: 2
Pickup Point: B
Drop Point: D
Pickup Time: 9

Output 1:
Taxi can be allotted.
Taxi-2 is allotted 
(Note: Since Taxi-1 would have completed its journey when second booking is done, so Taxi-2 from nearest point A which is free is allocated)
Input 3:
Customer ID: 3
Pickup Point: B
Drop Point: C
Pickup Time: 12

Output 1:
Taxi can be allotted.
Taxi-1 is allotted 
2) Display the Taxi details
Taxi No:    Total Earnings:
BookingID    CustomerID    From    To    PickupTime    DropTime    Amount
   
Output:
Taxi-1    Total Earnings: Rs. 400

1     1     A    B    9    10    200
3    3    B    C    12    13    200

Taxi-2 Total Earnings: Rs. 350
2    2    B    D    9    11    350 


My Code:
i tested this code in dev c++..  
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
 int distance(char *a,char *b);
 void taxiprint(int);
     int booking_id=1;
     int taxi1,taxi2,taxi3,taxi4;
     int taxi1_book,taxi2_book,taxi3_book,taxi4_book;
  int taxi_earning[4];
    struct taxi
    {
        int customer_id;
        char pickup_point[3];
        char drop_point[3];
        int pickup_time;
    }t[100];

    struct booking
    {
    // static int taxi_earning[4];
        int booking_id;
        int customer_id;
        char from[3];
        char to[3];
        int pickuptime;
        int droptime;
        int amount;
    }b[4][100];

void booking(struct booking *b,struct taxi t,int no)
{
b->customer_id=t.customer_id;
b->booking_id=booking_id++;
strcpy(b->from,t.pickup_point);
strcpy(b->to,t.drop_point);
b->pickuptime=t.pickup_time;
b->droptime =distance(t.pickup_point,t.drop_point)+t.pickup_time;
if(b->droptime>12)
{
 b->droptime-=12;
}
b->amount=100+((distance(t.pickup_point,t.drop_point)*15)-5)*10;
taxi_earning[no]+=b->amount;
}

int distance(char *a,char *b)
{
 char start=a[0];
 char stop=b[0];
 return (abs(start-stop));
}
void decrement()
{
 if(taxi1>0)
 taxi1--;
 if(taxi2>0)
 taxi2--;
 if(taxi3>0)
 taxi3--;
 if(taxi4>0)
 taxi4--;
}
void taxiprint(int taxino)
{
 printf("\n Taxi can be Allocated\n");
 printf("\n taxi- %d is allocated\n\n",taxino);
}
void display()
{
// printf("%d %d %d %d",taxi1_book,taxi2_book,taxi3_book,taxi4_book);
 if(taxi1_book>0)
 {
  printf("\nTaxi 1 \n total Earning= %d\n",taxi_earning[0]);
     printf("\n Booking_Id   Customer_Id   From  to  pickup_time  Drop_time  Amount\n");
  for(int i=0;i<taxi1_book;i++)
  {
   printf("%d     %d      %s      %s      %d     %d     %d\n",b[0][i].booking_id,b[0][i].customer_id,b[0][i].from,b[0][i].to,b[0][i].pickuptime,b[0][i].droptime,b[0][i].amount);
  }
 }
 if(taxi2_book>0)
 {
  printf("\nTaxi 2 \n total Earning= %d\n",taxi_earning[1]);
     printf("\n Booking_Id   Customer_Id   From  to  pickup_time  Drop_time  Amount\n");
  for(int i=0;i<taxi2_book;i++)
  {
   printf("%d     %d      %s      %s      %d     %d     %d\n",b[1][i].booking_id,b[1][i].customer_id,b[1][i].from,b[1][i].to,b[1][i].pickuptime,b[1][i].droptime,b[1][i].amount);
  }
 }if(taxi3_book>0)
 {
  printf("\nTaxi 3 \n total Earning= %d\n",taxi_earning[2]);
     printf("\n Booking_Id   Customer_Id   From  to  pickup_time  Drop_time  Amount\n");
  for(int i=0;i<taxi3_book;i++)
  {
   printf("%d     %d      %s      %s      %d     %d     %d\n",b[2][i].booking_id,b[2][i].customer_id,b[2][i].from,b[2][i].to,b[2][i].pickuptime,b[2][i].droptime,b[2][i].amount);
  }
 }if(taxi4_book>0)
 {
  printf("\nTaxi 1 \n total Earning= %d\n",taxi_earning[3]);
     printf("\n Booking_Id   Customer_Id   From  to  pickup_time  Drop_time  Amount\n");
  for(int i=0;i<taxi4_book;i++)
  {
   printf("%d     %d      %s      %s      %d     %d     %d\n",b[3][i].booking_id,b[3][i].customer_id,b[3][i].from,b[3][i].to,b[3][i].pickuptime,b[3][i].droptime,b[3][i].amount);
  }
 }
}
int main()
{

    while(1)
    {
        int user_choice,count,i;
        
        printf("\n...................Taxi_Booking..............................................\n");
        printf("\n 1.Booking  2.Details 3.exit \n");
        printf("Enter Choice:");
  scanf("%d",&user_choice);
        if(user_choice==1)
        {
            printf("\nnumber of Booking :");
            scanf("%d",&count);
            for(i=0;i<count;i++)
            {
                printf("\nInput %d:\n",i+1);
                printf("\nCustomer Id :");
                scanf("%d",&t[i].customer_id);
                printf("\npickup point :");
                scanf("%s",t[i].pickup_point);
                printf("\ndrop point :");
                scanf("%s",t[i].drop_point);
                printf("\npickup time :");
                scanf("%d",&t[i].pickup_time);
                if(taxi1==0)
                {
                booking(&b[0][taxi1_book++],t[i],0);
                taxi1=distance(t[i].pickup_point,t[i].drop_point);
                taxiprint(1);
                }
                else if(taxi2==0)
                {
                booking(&b[1][taxi2_book++],t[i],1);
                taxi2=distance(t[i].pickup_point,t[i].drop_point);
                taxiprint(2);
                }
                else if(taxi3==0)
                {
                 booking(&b[2][taxi3_book++],t[i],2);
                taxi3=distance(t[i].pickup_point,t[i].drop_point);
                taxiprint(3);
                }
                else if(taxi4==0)
                {
                 booking(&b[3][taxi4_book++],t[i],3);
                taxi4=distance(t[i].pickup_point,t[i].drop_point);
                taxiprint(4);
                }
                else
                {
                 printf("ALL Taxi Are Busy.. Please Try after Some time");
                }
                decrement();
            }
        }
        else if(user_choice==2)
        {
display();
        }
        else
        {
            return 0;
        }
    }
    
}
output screenshot:
 
 
 

Convert resultset object to list of map

Convert the resultset object to list of map In some cases, while we doing API automation, we need to fetch the value from the DB and hav...