Codechef Tyre problem solution

In this Tyre problem, we have N bikes and M cars on the road. each bike has 2 tires and the car has 4 tires. we need to find the total number of tires on the road.

Let's say we have 2 bikes and 1 car. and each bike has 2 tires and each car has 4 tires so there are 2*2 = 4 bike tires and 1*4 = 4 car tires. so total tyres are 4 + 4 = 8 on the road.

As an input first we have given an integer that is equal to the number of test cases and then we have the number of test cases with each line that contains N and M as an integer value of bike and car.

codechef tyre problem solution

Problem solution in C programming.

#include <stdio.h>
int main(void) {
    int t;
    scanf("%d",&t);
    int b,c,i;
    for(i=0;i<t;i++)
    {
        scanf("%d%d",&b,&c);
        printf("%d\n",2*b+4*c);
    }
    return 0;
} 


Here in the above code we read an integer input t for the number of test case. after that we run a for loop to scan and read the taste cases and then we print the number of tyres using the logic 2*(number of bikes) + 4*(number of cars).

Problem solution in C++ programming.

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int N, M;
        cin >> N >> M;

        cout << ((4 * M)+(2 * N)) << endl;
        /* code */
    }

    return 0;
}


Here in the above c++ code we first read the integer input for the test case. and then we run a while loop and then we print the number of tires on the output screen.

Problem solution in Java programming.

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=0;i<n;i++){
            int N = sc.nextInt();
            int M = sc.nextInt();
            System.out.println(N*2 + M*4);
        }
    }
}


Problem solution in Python programming.

# cook your dish here
t = int(input())
for i in range(0,t):
    n,m = map(int,input().split())
    tyre = (n*2)+(m*4)
    print(tyre)


Here first we read the input as an integer. and then we run a for loop till the range of integer for reading the test cases. and the using the map function we read the each and every test case input and then print the number of tyres value on the output screen.

Post a Comment

0 Comments