Showing posts with label code vita 2018. Show all posts
Showing posts with label code vita 2018. Show all posts

Air in the Balloons - Code Vita 2017 | Round 1

 Air in the balloons

 Problem:

You have been given 'N' number of spherical Balloons of different radius when filled. You have to fill one balloon per day and the last balloon will be filled on Nth day. There is some rate of air reduction 'K' per day from each balloon. Fill the balloons in such an order so that the sum of the volume of all the balloons is maximum on the day when all the balloons are filled.

Input Format:  First Line is an integer N giving the number of balloons.  Second line gives space separated N positive real numbers with up to 1 decimal place giving the radii of the balloons.   Third line gives K, the rate of reduction in the volume of air as a percentage.

Output Format:  Maximum sum of volumes of all the balloons on the Nth day when all the balloons are filled. Take 3.14 as the value of PI and give the answer to two decimal places (truncated by ignoring all the decimals from third onwards). Note that the truncation should happen only after computing the volume of all the balloons on the final day to maximum precision.

Constraints: 

 Number of balloons <= 10  Radius of balloons <=200

Example 1  

Input  
5
 8 4 6 10 3  1 0

Output 
 7117.88

Explanation  
If we fill the balloons in the order 3, 4, 6, 8, 10, their volumes on the fifth day are respectively  7 4.165544  1 95.33312  7 32.4992 1929.216  4 186.666667  A nd their sum is 7117.880531. Truncating the value two decimal places, we obtain 7117.88

Example 2  

Input  
7
3 .5 9 4 6.6 7 11 9.1  1 2.5

Output  
12555.35

Explanation  
If we inflate the balloons in the order 3.5 4 6.6 7 9 9.1 11, their volumes on the seventh day would be respectively  8 0.56025567  1 37.4322396 705.5574848  9 62.0256771  2 336.74875  2 760.581763 5572.453333 The sum of these volumes is 12555.3595 and truncating to two decimal places, we obtain 12555.35

Program

#include <stdio.h>
double rate(double y,float m,int k)
{
    for(int i=k;i>=1;i--)
    {
     y=y-y*(m/100);
    }
return y;
}
int main() {
int n,i,j;
double v,b[1000],t,v1,sum=0;
float a[1000],x;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%f ",&a[i]);
scanf("%f ",&x);
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j])
{
   t=a[i];
   a[i]=a[j];
   a[j]=t;
}
for(i=0;i<n;i++)
{
v=0;
v=(4*3.14*a[i]*a[i]*a[i])/3;
b[i]=rate(v,x,n-(i+1));
}
for(i=0;i<n;i++)
sum=sum+b[i];
printf("%.2f ",sum);
return 0;

}

You can also run it online 
IDE: https://ide.geeksforgeeks.org/iNcfre3Isa

our feedback are always welcome! If you have any doubt you can contact me or leave a comment!! Cheers!!!

Related Links 
One Egg :https://codepiggy.blogspot.com/2019/05/one-egg-code-vita-2017-round-2.html

Bank Compare | Code Vita 2018 | round 1

Bank Compare

 Problem Description

There are two banks; Bank A and Bank B. Their interest rates vary. You have received offers from both bank in terms of annual rate of interest, tenure and variations of rate of interest over the entire tenure.
You have to choose the offer which costs you least interest and reject the other.
Do the computation and make a wise choice.
The loan repayment happens at a monthly frequency and Equated Monthly Installment (EMI) is calculated using the formula given below :
EMI = loanAmount * monthlyInterestRate /
( 1 - 1 / (1 + monthlyInterestRate)^(numberOfYears * 12))

Constraints

1 <= P <= 1000000
1 <=T <= 50
1<= N1 <= 30
1<= N2 <= 30
Input Format
First line : P – principal (Loan Amount)
Second line : T – Total Tenure (in years).
Third Line : N1 is number of slabs of interest rates for a given period by Bank A. First slab starts from first year and second slab starts from end of first slab and so on.
Next N1 line will contain the interest rate and their period.
After N1 lines we will receive N2 viz. the number of slabs offered by second bank.
Next N2 lines are number of slabs of interest rates for a given period by Bank B. First slab starts from first year and second slab starts from end of first slab and so on.
The period and rate will be delimited by single white space.
Output
Your decision – either Bank A or Bank B.
Explanation
Example 1
Input
10000
20
3
5 9.5
10 9.6
5 8.5
3
10 6.9
5 8.5
5 7.9
Output
Bank B
Example 2
Input
500000
26
3
13 9.5
3 6.9
10 5.6
3
14 8.5
6 7.4
6 9.6
Output
Bank A
Program:

#include <stdio.h>
double power(double b,int a)
{
    int i;
    double pow=1;
    for(i=0;i<a;i++)
    {
        pow=pow*b;
    }
    return pow;
}
int main() {
double p,s,mi,sum,emi,j1,j,bank[5],sq;
int y,n,k,i,yrs,y1,l=0;
    scanf("%lf",&p);
scanf("%d",&y);
for(k=0;k<2;k++)
{
scanf("%d",&n);
sum=0;
for(i=0;i<n;i++)
{
    scanf("%d",&yrs);
    scanf("%lf",&s);
    mi=0;
    j=s/1200;
    j1=1+j;
    y1=yrs*12;
    sq=power(j1,y1);
    emi=p*(j/(1-(1/(sq))));
    mi=emi*y1;
    sum=sum+mi;
}
bank[l++]=sum;
}
if(bank[0]<bank[1])
printf("Bank A");
else
printf("Bank B");
return 0;
}

Output:

10000
20
3
5 9.5
10 9.6
5 8.5
3
10 6.9
5 8.5
5 7.9

Bank B
  
You can also run it in an online IDE: https://ide.geeksforgeeks.org/sPEYMvF71Y

If you have any doubts you can leave it in the comment section or contact me!!
Your feedback are welcomed so kindly leave your feedback below! Cheers!

Related Links: Stone Game- One Four

Date Time | Code Vita 2018 | round 1


Date Time

Problem Description

Arun and his sister Usha are challenging each other with some mathematical puzzles. Usha, the cleverer one, has come up with the idea of givingArun 12 distinct digits from 0 to 9, and have him form the largest date time in 2018 with them. Arun is a little nervous, and asks you to help him with a computer program.
Usha will give Arun 12 distinct digits. He needs to create a date time combination in the year 2018: the date in the MM/DD form (all four digits must be present), and the time in the format HH:MM (all four digits must be present). The date may be from 01/01 to 12/31 and the time may be from 00:00 to 23:59 (in the 24 hour format). The digits provided may be used only once in the answer that Arun gives.
If more than one date time combination may be formed, Arun needs to give the latest valid date time possible in the year 2018.

Constraints

Single digits (any of 0-9)

Input Format

A line consisting of a sequence of 12 (not necessarily distinct) single digits (any of 0-9) separated by commas. The sequence will be non-decreasing.

Output

The maximum possible valid date time in the year 2018. The output must be in the format
MM/DD HH:MM
If no date time can be constructed, the output should be 0
 

Explanation

Example1 :
Input
0,0,1,2,2,2,3,5,9,9,9,9
Output
12/30 22:59
Explanation
The 12 digits to be used by Arun are given.
The maximum valid date time using only the digits given, and with each digit used at most once is
12/30 22:59
This is the output.
Example 2
Input
3,3,3,3,3,3,3,3,3,3,3,3
Output
0
Explanation
As no digit less than 3 is present in the input, a valid month cannot be formed. Hence no valid Date time can be formed with the input digits.

Program

#include<stdio.h>
int isLeapYear(int y)
{
    if(y % 4 == 0)
    {
        if(y % 100 == 0)
        {
            if(y % 400 == 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        else
        {
            return 1;
        }
    }
    
    return 0;
}

int is_valid_date_time(int date_time_arr[], int n)
{
    int month;
    if(n >= 2)
    {
        month = date_time_arr[0] * 10 + date_time_arr[1];
        if(!(month >= 1 && month <= 12))
        {
            return 0;
        }
    }
    
    if(n >= 4)
    {
        int days_in_each_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        days_in_each_month[1] += isLeapYear(2018);
        
        int day = date_time_arr[2] * 10 + date_time_arr[3];
        if(!(day >= 1 && day <= days_in_each_month[month - 1]))
        {
            return 0;
        }
    }
    
    if(n >= 6)
    {
        int hour = date_time_arr[4] * 10 + date_time_arr[5];
        if(!(hour >= 0 && hour <= 23))
        {
            return 0;
        }
    }
    
    if(n >= 8)
    {
        int min = date_time_arr[6] * 10 + date_time_arr[7];
        if(!(min >= 0 && min <= 59))
        {
            return 0;
        }
    }
    
    return 1;
}

int isFound = 0;
int max_time_in_2018[8] = {0};

int is_max(int inp_arr[])
{
    for(int i = 0; i < 8; i ++)
    {
        if(max_time_in_2018[i] == inp_arr[i])
        {
            continue;
        }
        else if(max_time_in_2018[i] >inp_arr[i])
        {
            return 0;
        }
        else 
        {
            return 1;
        }
    }
    
    return 0;
}

void time_computing(int inp_arr[], 
                    int date_time_arr[], int sel_cnt,
                    int used[])
{
    if(!is_valid_date_time(date_time_arr, sel_cnt)) 
    {
        return;
    }
    
    if(sel_cnt == 8)
    {
        if(is_valid_date_time(date_time_arr, sel_cnt))
        {
            isFound = 1;
            if(is_max(date_time_arr))
            {
                for(int i = 0; i < 8; i++)
                {
                    max_time_in_2018[i] = date_time_arr[i];
                }
            }
        }
        
        return;
    }
    
    // Select current item
    for(int i = 0; i< 12; i++)
    {
        if(used[i] == 1)
        {
            continue;
        }
        
        date_time_arr[sel_cnt] = inp_arr[i];
        used[i] = 1;
        time_computing(inp_arr,date_time_arr, sel_cnt + 1, used);
        used[i] = 0;
    }              
}

int main()
{
    int inp_arr[12], date_time_arr[8];
    scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
          &inp_arr[0],&inp_arr[1],&inp_arr[2],&inp_arr[3],
          &inp_arr[4],&inp_arr[5],&inp_arr[6],&inp_arr[7],
          &inp_arr[8],&inp_arr[9],&inp_arr[10],&inp_arr[11]);

    int used[12] = {0};
    
    time_computing(inp_arr, date_time_arr, 0, used);
    if(isFound == 1)
    {
        printf("%d%d/%d%d %d%d:%d%d",
         max_time_in_2018[0],max_time_in_2018[1],max_time_in_2018[2],max_time_in_2018[3],
         max_time_in_2018[4],max_time_in_2018[5],max_time_in_2018[6],max_time_in_2018[7]);
    }
    else
    {
        printf("0");
    }
    
    return 0;
}

Output

0,0,1,2,2,2,3,5,9,9,9,9

12/30 22:59

You can also run it on an online IDE: https://ide.geeksforgeeks.org/XZImlFQrQa

Your comments and feedback are welcomed!! If you have any doubts do contact me! Cheers!

Related Links: Parallelograms 2018

Super Market Problem | TCS Code Vita 2023 - Zone 1 | Super Market TCS Code Vita 2023 Solution | Code Vita 2023 | Code Vita 2023 season 11 solution

 Problem Description: In a Super market we will find many variations of the same product. In the same way we can find many types of rice bag...