Park the vehicles

PROBLEM LINK

[PARK THE VEHICLES] (CodeChef: Practical coding for everyone)

PRE-REQUISITES

C Programming Language

PROBLEM:

DESCRIPTON

If there is a space to park the vehicles then some n number of vehicles are parked there and then count how many are of cars, and how many of our scooters and note the arrival time and the departure time, display the order of parked vehicles, and the color of vehicle, if he wants to take the vehicle from the parking he has to tell the number of vehicles if the number is wrong he can’t able to take the vehicle from parking in that case he has to tell the car model and the color of the vehicle and also the RC book of the vehicle and also he has to calculate the parking fees based on the time he kept.

Input

1

25

bikes

blue

pulsar

11:00

12:00

Output

Vehicle number: 25

Vehicle type: bikes

Vehicle color: blue

Vehicle model: pulsar

Arrival time: 11:00

Departure time: 12:00

Number of cars: 0

Number of bikes: 1

SOLUTION :

#include<stdio.h>
typedef struct {
int hr; //hours
int mi; //minutes
} time;

typedef struct {
int number;
char type[255];
char color[255];
char model[255];
time arrival;
time departure;
} vehicle;

time makeTime(int l, int m) {
time res;
res.hr = l, res.mi = m;

return res;

}

vehicle readVehicle() {
vehicle res;
int l, m;
char s[255];

scanf("%d", &l);
res.number = l;

scanf("%s", &s);
strcpy(res.type, s);

scanf("%s", &s);
strcpy(res.color, s);

scanf("%s", &s);
strcpy(res.model, s);

scanf("%d:%d", &l, &m);
res.arrival = makeTime(l, m);

scanf("%d:%d", &l, &m);
res.departure = makeTime(l, m);

return res;

}

void printVehicle(vehicle l) {
printf(“Vehicle number:%d\n”, l.number);
printf(“Vehicle type:%s\n”, l.type);
printf(“Vehicle color:%s\n”, l.color);
printf(“Vehicle model:%s\n”, l.model);

printf("Arrival time: %d%d:%d%d\n", l.arrival.hr / 10, l.arrival.hr % 10, l.arrival.mi / 10, l.arrival.mi % 10);
printf("Departure time: %d%d:%d%d\n", l.departure.hr / 10, l.departure.hr % 10, l.departure.mi/ 10, l.departure.mi% 10);

}

int main() {
int n, i, t;
scanf(“%d”, &n);

vehicle *l = malloc(sizeof(vehicle)*n);

for (i = 0; i < n; i++) {

l[i] = readVehicle();
}

int numberOfCars = 0, numberOfbikes = 0;

for (i = 0; i < n; i++) {

printVehicle(l[i]);

if (strcmp(l[i].type, “car”) == 0) {
numberOfCars++;
}
if (strcmp(l[i].type, “bikes”) == 0) {
numberOfbikes++;
}
}

printf("Number of cars: %d\nNumber of bikes: %d\n", numberOfCars, numberOfbikes);

return 0;

}