Saturday, April 27, 2019

Compatible Arrays using Functions

Problem Description

Two arrays are said to be compatible if they are of the same size and if the ith element in the first array is greater than or equal to the ith element in the second array for all i.Write a program to find whether 2 arrays are compatible or not.

Input Format:

Input consists of 2n+1 integers. The first integer corresponds to n , the size of the array. The next n integers correspond to the elements in the first array. The last n integers correspond to the elements in the second array. Assume that the maximum value of n is 15.
Test Case 1

Input (stdin)
5

2 3 6 8 1

1 1 1 1 1

Expected Output

Compatible
Test Case 2

Input (stdin)
5

2 3 6 8 1

1 1 1 2 2

Expected Output

Incompatible

Solution

#include<stdio.h>
int main(){
int n,a[20],b[20],i,flag=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++){
scanf("%d",&b[i]);
if(a[i]<b[i])
flag=1;
}
if(flag)
printf("Incompatible");
else
printf("Compatible");


return 0;
}

IO 31

  • Problem Description

    Pranav intelligent in playing riddle with numbers so, he gave his sister a puzzle to solve in which she need to solve by adding the left side integral part of two decimal numbers.

    Explanation:

    Raju gave his sister two decimal numbers : 23.44 and 33.22 , His sister need to identify the left side integral part of given numbers are 23 and 33 . Finally the added output value is 56.

    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)
    12.55

    11.56

    Expected Output
    sum=23
  • Test Case 2

    Input (stdin)
    0.11

    0.11

    Expected Output
    sum=0
  • Program
  • #include <stdio.h>
    int main()
    {
    float a,b;
    int c,d,e;
    scanf("%f%f",&a,&b);
    d=a;
    e=b;
    c=d+e;
    printf("sum=%d",c);
    return 0;
    }

IO 10

#include <stdio.h>
int main()
{
int a,c;
scanf ("%d%d",&a,&c);
    c = a;
printf
("c=d \n", c);
c
+= a;
printf
("c+=%d \n", c);
c
-= a;
printf
("c-=%d \n", c);
c
*= a;
printf
("c*=%d \n", c);
c
/= a;
printf
("c/=%d \n", c);
c
%= a;
printf
("c%=%d \n", c);
return 0;
}

Remove Alphabets

#include<stdio.h>

int main()
{
char line[150];
int i, j;
scanf ("%[^\n]s",line)
;

for(i = 0; line[i] != '\0'; ++i)
{
while (!( (line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z') || line[i] == '\0') )
{
for(j = i; line[j] != '\0'; ++j)
{
line
[j] = line[j+1];
}
line
[j] = '\0';
}
}
puts
(line);
return 0;
}

Thursday, April 25, 2019

SUM OF 6 NUMBERS

  • Problem Description

    Print the sum of 6 numbers using array and pointers
  • Test Case 1

    Input (stdin)
    1 2 3 4 5 6

    Expected Output
    21
  • Test Case 2

    Input (stdin)
    1 1 1 2 2 2

    Expected Output
    9
Solution

#include<stdio.h>
int main() {
   int numArray[10];
   int i, sum = 0;
   int *ptr;
 
   for (i = 0; i < 10; i++)
      scanf("%d", &numArray[i]);
 
   ptr = numArray;
 
   for (i = 0; i < 6; i++) {
      sum = sum + *ptr;
      ptr++;
   }
 
   printf("%d", sum);
  return 0;
}

THREE MARKS

  • Problem Description

    Mani Working as a professor in ABC college, have 
    to get students three subjects points.

    so he planned to do one program to implement
    structure concept.

    Input

    3 3 5

    Output

    3 3 5
  • CODING ARENA
  • #include <stdio.h>
    struct display
    {
      int a,b,c;
    }s;
    int main()
    {
      struct display s;
      scanf("%d%d%d",&s.a,&s.b,&s.c);
      printf("%d\n%d\n%d\n",s.a,s.b,s.c);
    return 0;
    }
  • Test Case 1

    Input (stdin)
    3 3 5

    Expected Output
    3

    3

    5
  • Test Case 2

    Input (stdin)
    3 3 6

    Expected Output
    3

    3

    6

WHERE ARE THE MARKS?

  • Problem Description

    Ganapathy working as a professor in ABC college, have 
    to get students three subjects points.

    so he planned to do one program to implement
    structure concept.

    Input

    3 3 5

    Output

    3 3 5
  • Test Case 1

    Input (stdin)
    3 3 5

    Expected Output
    3 3 5
  • Test Case 2

    Input (stdin)
    3 3 6

    Expected Output
    3 3 6
Solution

#include <stdio.h>
struct display
{
  int a,b,c;
}s;
int main()
{
  struct display s;
  scanf("%d%d%d",&s.a,&s.b,&s.c);
  printf("%d %d %d",s.a,s.b,s.c);
 return 0;
}

Alphabet Game

  • Problem Description

    Not everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read.

    He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff can read a word iff it consists only of the letters he knows.

    Now Chef is curious about which words his brother will be able to read, and which are not. Please help him!
    Input

    The first line of the input contains a lowercase Latin letter string S, consisting of the letters Jeff can read. Every letter will appear in S no more than once.

    The second line of the input contains an integer N denoting the number of words in the book.

    Each of the following N lines contains a single lowecase Latin letter string Wi, denoting the ith word in the book.
    Output

    For each of the words, output "Yes" (without quotes) in case Jeff can read it, and "No" (without quotes) otherwise.
    Constraints

    1 <= |S| <= 26
    1 <= N <= 1000
    1 <= |Wi| <= 12
    Each letter will appear in S no more than once.
    S, Wi consist only of lowercase Latin letters.

    Subtasks

    Subtask #1 (31 point): |S| = 1, i.e. Jeff knows only one letter.
    Subtask #2 (69 point) : no additional constraints
  • Test Case 1

    Input (stdin)
    eat

    2

    tea

    ate

    Expected Output
    Yes

    Yes
  • Test Case 2

    Input (stdin)
    tiger

    3

    get

    tier

    great

    Expected Output
    Yes

    Yes

    No
Solution

# include <stdio.h>
# include <string.h>
int main()
{
int n,i,j,k;char s[1000];char c1[1000];int x,c;
scanf("%s",s);
int y=strlen(s);
scanf("%d",&n);
for(i=0;i<n;i++)
{
    c=0;
    scanf("%s",c1);
     x=strlen(c1);
     for(j=0;j<x;j++)
     {
         for(k=0;k<y;k++)
         {
           if(c1[j]==s[k])
                c++;
         }
     }
     if(c==x)
        printf("Yes\n");
     else
        printf("No\n");
}
 
    return 0;
}
 

Average Scale

A grocer has a sale of Rs. s1, Rs. s2, Rs. s3, Rs. s4 and Rs. s5 for 5 consecutive months. How much sale must he have in the sixth month so that he gets an average sale of Rs. x?

Write a C program to compute the sale in the 6th month.

Input Format: 
Input consists of 5 integers and 1 float. The five integers correspond to s1, s2, s3, s4 and s5. The float input corresponds to x.

Output Format: 
Refer sample input and output for formatting specifications. The float values are displayed correct to 2 decimal places.

Sample Input and Output: 
[All text in bold corresponds to input and the rest corresponds to output]
Enter sale in first month
6435
Enter sale in second month
6927
Enter sale in third month
6855
Enter sale in fourth month
7230
Enter sale in fifth month
6562
Enter the average sales in 6 months
6500
The sale in the sixth month is Rs.4991.00

Code:
  #include<stdio.h>
int main(){
float s[5],a;
scanf("%f",&s[0]);
scanf("%f",&s[1]);
scanf("%f",&s[2]);
scanf("%f",&s[3]);
scanf("%f",&s[4]);
scanf("%f",&a);
printf("sale=%.2f",(6*s[5])-(s[0]+s[1]+s[2]+s[3]+s[4]));
return 0;
}

Tuesday, April 23, 2019

Little Elephant and Movies

Problem Description 
  
Little Elephant from Zoo of Lviv likes to watch movies. 
  
There are N different movies (numbered from 0 to N 1) he wants to watch in some order. Of course, he will watch each movie exactly once. The priority of ith movie is Pi. 
  
A watching of a movie is called exciting if and only if one of the following two conditions holds: 
  
This is the first watching. 
The priority of this movie is strictly greater than the maximal priority of the movies watched so far. 
Let us call the number of exciting watchings the excitingness of the order. 
  
Help him to find the number of different watching orders whose excitingness does not exceed K. Since the answer can be large, print it modulo 1000000007 (109+7). 
  
Input 
  
The first line of input contains an integer T, denoting the number of test cases. Then T test cases follow. 
  
The first line of each test case contains two space-separated integers N and K. The next line contains N space-separated integers P1, P2, ..., PN. 
  
Output 
  
For each test case, print the number of different watching orders having at most K excitingness modulo 1000000007 (109+7). 
  
Constraints 
  
1<=T<=10 
1<=K<=N<=200 
1<=Pi<=200 
  
In the first case, there are two boring watching orders whose excitingness not greater than K=1: [3, 1, 2], [3, 2, 1]. Both watching orders have one exciting watching: the first watching. 
  
In the second case, every watching order has at most 3 excitingness. 
Test Case 1 
  
Input (stdin) 

  
3 1 
  
3 1 2 
  
4 3 
  
1 2 2 3 
  
Expected Output 
  

  
24 
Test Case 2 
  
Input (stdin) 

  
Expected Output 
  
0

Solution
#include<stdio.h>

#define MAX 210
#define MOD 1000000007
typedef unsigned int UD;
typedef unsigned long long ULL;

UD comb[MAX][MAX]={0};
UD fact[MAX]={0};

/*UD partfact2(UD m, UD n)
{
UD ans;
for(i=0;i<(n-1);i++)
{
m++;
ans=((ULL)ans*m)%MOD;
}
ans = ((ULL)comb[m+n-1][m]*fact[n])%MOD;
//ans = ((ULL)ans*n)%MOD;
return ans;
}

UD partfact1(UD m, UD n)
{
UD ans;
for(i=0;i<(n-1);i++)
{
m++;
ans=((ULL)ans*m)%MOD;
}
//ans = ((ULL)ans*temp)%MOD;
ans = ((ULL)comb[m+n-1][m-1]*fact[n])%MOD;
return ans;
}*/

UD solve()
{
UD N,K,i,num,count=0,m=0,n,j,fact1,fact2,ans=0;
UD P[MAX]={0},Karray[MAX][2]={0};
scanf("%u %u",&N,&K);
for(i=0;i<N;i++)
{
scanf("%u",&num);
P[num]++;
}
for(i=1;i<MAX;i++)
{
if(P[i]>0)
{
count=i;
}
}
n=P[count];
Karray[1][1]=((ULL)comb[m+n-1][m]*fact[n])%MOD;
Karray[1][0]=Karray[1][1];
for(i=count-1;i>0;i--)
{

m=m+n;
n=P[i];
if(n==0)
{
continue;
}
else
{
fact1=((ULL)comb[m+n-1][m-1]*fact[n])%MOD;
fact2=((ULL)comb[m+n-1][m]*fact[n])%MOD;
for(j=1;j<=(count-i+1) && j<=K;j++)
{
Karray[j][0]=Karray[j][1];
Karray[j][1]=((ULL)((ULL)Karray[j][0]*fact1)%MOD + ((ULL)Karray[j-1][0]*fact2)%MOD)%MOD;
}

}
}

for(i=1;i<=K;i++)
{
ans=((ULL)ans+Karray[i][1])%MOD;
}
return ans;
}

int main()
{

UD T,ans,i,j;
// UD comb[MAX][MAX]={0};
for(i=0;i<MAX;i++)
{
comb[i][0]=1;
for(j=1;j<=i;j++)
{
comb[i][j]=((ULL)comb[i-1][j] + comb[i-1][j-1])%MOD;
}
}
fact[0]=1;
for(i=1;i<MAX;i++)
{
fact[i]=((ULL)fact[i-1]*i)%MOD;
}
scanf("%u",&T);
while(T--)
{
ans=solve();
/*for(i=0;i<MAX;i++)
{
P[i]=0;
Karray[i][0]=0;
Karray[i][1]=0;
}*/
printf("%u\n",ans);
}
return 0;
}

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...