Canna

Saturday, 15 June 2019

Differenzia

  • Problem Description

    In a country named Differenzia the minors and senior citizens are not eligible to vote. Only people aged between 18 to 60 (both inclusive) are eligible to vote. Write a program to determine a person in Differenzia is eligible to vote.
  • Test Case 1

    Input (stdin)
    18
    
    
    Expected Output
    Eligible
  • Test Case 2

    Input (stdin)
    17
    
    
    Expected Output
    Not Eligible
  • Program
  • #include <stdio.h>
    int main()
    {
     int a;
      scanf("%d",&a);
      if(a>=18&&a<=60)
        printf("Eligible");
      else
        printf("Not Eligible");
     return 0;
    }

Adding two distances

  • Problem Description

    1. Create a Structure called "Distance" 

    2. Create two data members of "Distance Structure" feet(int), inch(float) 

    3. Create three structure variables as d1, d2 and sumOfDistances 4. Get two distances and add the feet and inches.

    Mandatory:

    To add the distance using the structure variables as follows

    1. sumOfDistances.feet=d1.feet+d2.feet

    2 sumOfDistances.inch=d1.inch+d2.inch
  • Test Case 1

    Input (stdin)
    23 8.6
    
    34 2.4
    
    
    Expected Output
    Sum of distances=57 feet and 11.00 inches
  • Test Case 2

    Input (stdin)
    25 11.9
    
    34 2.5
    
    
    Expected Output
    Sum of distances=59 feet and 14.40 inches
  • Program
  • #include <stdio.h>
    
    struct Distance
    {
      int feet;
      float inch;
    }d1,d2,sumOfDistances;
    int main()
    {
      scanf("%d %f\n",&d1.feet,&d1.inch);
      scanf("%d %f\n",&d2.feet,&d2.inch);
      {
        sumOfDistances.feet=d1.feet+d2.feet;
        sumOfDistances.inch=d1.inch+d2.inch;
        printf("Sum of distances=%d feet and %.2f inches",sumOfDistances.feet,sumOfDistances.inch);
      }
     return 0;
    }

How many bits?

  • Problem Description

    Sasha ask Diya to write a program to get minimum number of bits to store an integer number. Devi thinks a lot but she could not able to do this.Can you help her to derive a solultion for this?
  • Test Case 1

    Input (stdin)
    127
    
    
    Expected Output
    7
  • Test Case 2

    Input (stdin)
    32767
    
    
    Expected Output
    15
  • Program
  • #include <stdio.h>
    int countbit(int);
    int main()
    {
      int num;
      scanf("%d",&num);
      printf("%d",countbit(num));
      return 0;
    }
    int countbit(int n)
    {
      int count=0,i;
      if(n==0) return 0;
      for(i=0;i<32;i++)
      {
        if((1<<i)&n)
          count=i;
      }
      return ++count;
    
    
    
    }

Sorting Names

  • Problem Description

    Professor Manvi has to take attendance for her class, but the names are scattered. She has to sort the names in alphabetical order. Write a code to perform sorting
  • Test Case 1

    Input (stdin)
    4
    
    suba
    
    bala
    
    deepa 
    
    arun
    
    
    Expected Output
    arun
    
    bala
    
    deepa
    
    suba
  • Test Case 2

    Input (stdin)
    4
    
    akashi
    
    jero
    
    mani
    
    parkavi
    
    
    Expected Output
    akashi
    
    jero
    
    mani
    
    parkavi
  • Program
  • #include <stdio.h>
    #include <string.h>
    int main()
    {
      int i,j,num;
      char str[50][50],temp[25];
      scanf("%d",&num);
      for(i=0;i<num;i++)
      {
        scanf("%s",str[i]);
      }
      for(i=0;i<num;i++)
      {
        for(j=i+1;j<num;j++)
        {
          if(strcmp(str[i],str[j])>0)
             {
               strcpy(temp,str[i]);
               strcpy(str[i],str[j]);
               strcpy(str[j],temp);
             }
          }
      }
             for(i=0;i<num;i++)
             {
             printf("\n%s",str[i]);
             }
     return 0;
    }

Multiply by 5

  • Problem Description

    Ram play a game with guna to tell if ram say number gun have to reply
    the number multiplied by 5 value, for example if ram say 2 guna has to reply 10.
    using structure concept implement it.


    Input Method

    Integer ranges from 1 to 999

    Output Method

    Value multiplied by 5

  • Test Case 1

    Input (stdin)
    3
    
    
    Expected Output
    15
  • Test Case 2

    Input (stdin)
    4
    
    
    Expected Output
    20
  • Program
  • #include <stdio.h>
    int main()
    {
     int a,b;
     scanf("%d",&a);
      b=a*5;
      printf("%d",b);
     return 0;
    }

Computing X

  • Problem Description

    The cost prince of n articles is the same as the selling price of X articles . If the profit is p% then what is the value of x?

    Input format:

    The first input is an integer which corresponds to n the second is an integer which corresponds to p

    Output Formt:

    Refer sample Input and output for formatting Specifications

    The float values are displayed correct to 2 decimal places.
  • Test Case 1

    Input (stdin)
    12.5
    
    14.5
    
    
    Expected Output
    10.92
  • Test Case 2

    Input (stdin)
    5.0
    
    6.0
    
    
    Expected Output
    4.72
  • Program
  • #include <stdio.h>
    int main()
    {
      float cp,sp,x;
      scanf("%f%f",&cp,&sp);
      x=(cp*100)/(sp+100);
      printf("%.2f",x);
        
    
     return 0;
    }

Rectangular Object

  • Problem Description

    Subbu needs to make a rectangular box for his physics class project. He has bought P cm of wire and S cm2 of special paper. He would like to use all the wire (for the 12 edges) and paper (for the 6 sides) to make the box.

    What is the largest volume of the box that Johnny can make?
    Input

    The first line contains t, the number of test cases (about 10). Then t test cases follow.

    Each test case contains two integers P and S in a line (1<= P <= 40000, 1 <= S <= 20000). You may assume that there always exists an optimal solution for the given input cases.
    Output

    For each test case, print a real number that is the largest volume of the box that Johnny can make, rounded to two decimal places.
  • Test Case 1

    Input (stdin)
    2
    
    20 14
    
    20 16
    
    
    Expected Output
    3.00
    
    4.15
  • Test Case 2

    Input (stdin)
    2
    
    40 20
    
    30 15
    
    
    Expected Output
    2.64
    
    2.02
  • Program
  • #include<stdio.h>
    #include<math.h>
    int main()
    {
    
        int t,p,s;
        float v,h,d;
        scanf("%d",&t);
        while(t--){
            scanf("%d %d",&p,&s);
            d=sqrt(p*p-24*s);
            h=(p-d)/12;
            v=(h*h*h)-((h*h*p)/4)+((s*h)/2);
            printf("%.2f\n",v);
        }return 0;
    }

Pointers - 10

  • Problem Description

    Write a program to add two integers using functions use call by address technique of passing parameters and also illustrate the concept of pointer variables can be used to access the strings.

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.

  • Test Case 1

    Input (stdin)
    6
    
    7
    
    
    Expected Output
    The sum of the numbers is 13
    
    Accessing a string using pointer
    
    Hello
  • Test Case 2

    Input (stdin)
    9
    
    10
    
    
    Expected Output
    The sum of the numbers is 19
    
    Accessing a string using pointer
    
    Hello
  • Program
  • #include <stdio.h>
    int main()
    {
      int a,b,c;
      scanf("%d%d",&a,&b);
      c=a+b;
      printf("The sum of the numbers is %d\n",c);
      printf("Accessing a string using pointer\n");
      printf("Hello");
    
     return 0;
    }
  • 
    

Aloo Kachori

  • Problem Description

    kenny has received a package of N ingredients from Aloo uncle and Kachori aunty as their Christmas gift. kenny decides to make dishes with every possible combination of these N ingredients. (Note: A dish with 0 ingredients is also possible. kenny uses it as an excuse for serving air to their airy customers). Every ingredient from the package has a taste score between 1 and 10.

    Now kenny has customers on two planets, planet A and planet B. People from planet A like all the ingredients very much. And hence for every dish given to them, planet A will pay kenny an amount, which, in Alterian dollars, equals the sum of the taste scores of all the ingredients present in the dish minus the sum of the taste scores of all the ingredients not present in the dish.

    People from planet B dont like the ingredients at all. So for every dish given to planet B, planet B will pay kenny Alterian dollars equal to the sum of the taste scores of all the ingredients not present in the dish minus the sum of the taste scores of all the ingredients present in the dish.

    kenny can only make a single dish from a particular combination of ingredients. And they can send a dish either to planet A or planet B, but not both. You have to find out the maximum amount of money kenny will make by distributing all the dishes made with these ingredients on planet A and planet B.

    Report the maximum amount modulo 107.
    Input

    The first line contains T, the number of test cases.

    Each test case begins with N, the number of ingredients

    The next line for the test case contains N space-separated integers, which are the taste scores of the ingredients.
    Output

    For each test case, output the value as asked in a separate line.
    Constraints

    1 <= T <= 100
    1 <= N <= 1000
    1 <= Taste scores of ingredients <= 10
    1 <= Sum of N over all Test Cases <= 1000
  • Test Case 1

    Input (stdin)
    1
    
    3
    
    1 2 3
    
    
    Expected Output
    24
  • Test Case 2

    Input (stdin)
    2
    
    2
    
    1 3
    
    3
    
    1 4 5
    
    
    Expected Output
    12
    
    40
  • Program
  • #include <stdio.h>
    #include <stdlib.h>
    #define MOD 10000000
    int main()
    {
      int T,N,sum,values[1000],i,j;
      long long dp[10001],total;
      scanf("%d",&T);
      while(T--)
      {
        scanf("%d",&N);
        sum=0;
        for(i=0;i<N;i++)
        {
          scanf("%d",&values[i]);
          sum=sum+values[i];
        }
        for(i=0;i<=sum;i++)
        {
          dp[i]=0;
          dp[0]=1;
        }
        for(i=0;i<N;i++)
        {
          for(j=sum;j>=0;j--)
          {
            if(dp[j]>0)
            {
              dp[j+values[i]]=((dp[j+values[i]])+(dp[j]))%MOD;
            }
          }
        }
        total=0;
        for(i=0;i<=sum;i++)
        {
          if(dp[i]>0)
          {
            long long inc=((long long)((((long long)abs(sum-2*i)))*(dp[i])))%MOD;
            total=(total+inc)%MOD;
          }
        }
          printf("%Ld\n",total);
      }
      return 0;
    }

Lucy

  • Problem Description

    Lucy is celebrating her 15th birthday. Her father promised her that he will buy her a new computer on her birthday if she solves the question asked by him. He asks Lucy to find whether the year on which she had born is leap year or not. Help her to solve this puzzle so that she celebrates her birthday happily. If her birth year is 2016 and it is a leap year display 2016 is a leap year.? Else display 2016 is not a leap year and check with other leap year conditions.
  • Test Case 1

    Input (stdin)
    1900
    
    
    Expected Output
    1900 is not a leap year
  • Test Case 2

    Input (stdin)
    2016
    
    
    Expected Output
    2016 is a leap year
  • Program
  • #include <stdio.h>
    int main()
    {
      int a;
      scanf("%d",&a);
      if(a%400==0)
      {
        printf("%d is a leap year",a);
      }
      else if(a%100==0)
      {
        printf("%d is not a leap year",a);
      }
      else if(a%4==0)
      {
        printf("%d is a leap year",a);
      }
      else
        printf("%d is not a leap year",a);
      return 0;
    }

Adding two numbers

  • Problem Description

    Add two numbers using pointers
  • Test Case 1

    Input (stdin)
    5
    
    4
    
    
    Expected Output
    The sum of the entered numbers is=9
  • Test Case 2

    Input (stdin)
    9
    
    10
    
    
    Expected Output
    The sum of the entered numbers is=19
  • Program
  • #include <stdio.h>
    int main()
    {
     int a,b,c;
      scanf("%d%d",&a,&b);
      c=a+b;
      printf("The sum of the entered numbers is=%d",c);
     return 0;
    }

NUMBER OF VOWELS AND CONSTANT

  • Problem Description

    Count vowels and constants in a given string using pointers
  • Test Case 1

    Input (stdin)
    welcome
    
    
    Expected Output
    3 4
  • Test Case 2

    Input (stdin)
    hello
    
    
    Expected Output
    2 3
  • Program
  • #include <stdio.h>
    int main()
    {
      char str[20];
      char *ptr;
      int cntV;
      int cntC;
     scanf("%s",str);
      ptr=str;
      cntV=cntC=0;
      while(*ptr!='\0')
        {
        if(*ptr=='a'||*ptr=='e'||*ptr=='i'||*ptr=='o'||*ptr=='u')
          cntV++;
          else
            cntC++;
      ptr++;
        }
      printf("%d %d\n",cntV,cntC);
    
      
      
          
        
    
      
    
     return 0;
    }

Pointer 3

  • Problem Description

    Write a program to subtract two double values using pointer

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output
  • Test Case 1

    Input (stdin)
    4
    
    5
    
    
    Expected Output
    -1.00
  • Test Case 2

    Input (stdin)
    10
    
    6
    
    
    Expected Output
    4.00
  • Program
  • #include <stdio.h>
    int main()
    {
      float a,b,c;
      scanf("%f%f",&a,&b);
      c=a-b;
      printf("%f",c);
      
     return 0;
    }

Pointers - 10

  • Problem Description

    Write a program to add two integers using functions use call by address technique of passing parameters and also illustrate the concept of pointer variables can be used to access the strings.

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.

  • Test Case 1

    Input (stdin)
    6
    
    7
    
    
    Expected Output
    The sum of the numbers is 13
    
    Accessing a string using pointer
    
    Hello
  • Test Case 2

    Input (stdin)
    9
    
    10
    
    
    Expected Output
    The sum of the numbers is 19
    
    Accessing a string using pointer
    
    Hello
  • Program
  • #include <stdio.h>
    int main()
    {
      int a,b,sum;
      scanf("%d%d",&a,&b);
      sum=a+b;
      printf("The sum of the numbers is %d\n",sum);
      printf("Accessing a string using pointer\n");
      printf("Hello\n");
    
     return 0;
    }

Pointer - 26

  • Problem Description

    Write a program to compare two arrays using pointers.

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.
  • Test Case 1

    Input (stdin)
    5
    
    1 2 3 4 5
    
    5
    
    5 4 3 2 1
    
    
    Expected Output
    Arrays are not equal
  • Test Case 2

    Input (stdin)
    4
    
    1 2 3 4
    
    4
    
    1 2 3 4
    
    
    Expected Output
    Arrays are equal
  • Program
  • #include <stdio.h>
    int main()
    {
      int a,b,i,j,f;
      scanf("%d",&a);
      int arr[a];
      for(j=0;j<a;j++)
      {
        scanf("%d",&arr[j]);
      }
      scanf("%d",&b);
      int arr1[b];
      for(i=0;i<b;i++)
      {
        scanf("%d",&arr1[i]);
      }
      for(i=0;i<a;i++)
      {
        if(arr[i]!=arr1[i])
        {
          f=1;
          break;
        }
      }
      if(f==1)
        printf("Arrays are not equal");
      else
        printf("Arrays are equal");
        
                     
        
    
    
     return 0;
    }

Pointers - 24

  • Problem Description

    Write a function that accepts a string using pointers. In the function ,delete all the occurrences of a given character and display the modified string on the screen

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.

  • Test Case 1

    Input (stdin)
    SRM University
    
    S
    
    
    Expected Output
    RM University
  • Test Case 2

    Input (stdin)
    SRM University
    
    R
    
    
    Expected Output
    SM University
  • Program
  • #include <stdio.h>
    #include<string.h>
    int main()
    {
      char str[15],ch,cat[10];
      scanf("%s%s",str,cat);
      scanf("%s",&ch);
      int i=0,j,len;
      len=strlen(str);
      for(i=0;i<len;i++)
      {
        if(str[i]==ch)
        {
          for(j=i;j<len;j++)
          {
            str[j]=str[j+1];
          }
          len--;
          i--;
        }
      }
      printf("%s ",str);
      printf("%s",cat);
    
     return 0;
    }

PRINT THE GIVEN STRING

  • Problem Description

    Print a string using Pointer
  • Test Case 1

    Input (stdin)
    Cse
    
    
    Expected Output
    Cse
  • Test Case 2

    Input (stdin)
    eee
    
    
    Expected Output
    eee
  • Program
  • #include <stdio.h>
    #include <string.h>
    int main()
    {
      char str[100];
      scanf("%s",str);
      printf("%s",str);
    
    
        
     return 0;
    }

Swap

  • Problem Description

    Write a program to swap two numbers and print the swapped number in float.
  • Test Case 1

    Input (stdin)
    10 78
    
    
    Expected Output
    78.00
    
    10.00
  • Test Case 2

    Input (stdin)
    104 239
    
    
    Expected Output
    239.00
    
    104.00
  • Program
  • #include <stdio.h>
    int main()
    {
    int a,b,t;
      
      scanf("%d %d",&a,&b);
      t=a;
      a=b;
      b=t;
      printf("%.2f\n%.2f",1.0*a,1.0*b);
      
     return 0;
    }