Problem Description
The year is divided into four seasons: spring, summer, fall and winter. While the exact dates that the seasons change vary a little bit from year to year because of the way that the calendar is constructed, we will use the following dates for this exercise:
Season First day
Summer March 20
Spring June 21
Fall September 22
Winter December 21
Create a program that reads a month and day from the user. The user will enter the name of the month as a string, followed by the day within the month as an integer.
Then your program should display the season associated with the date that was entered.
Note: Enter First three letter for month example: Jan for january, Feb for Feburary ans so on....and first letter of the month should be capitalCODING ARENA
#include <stdio.h>
#include<string.h>
int main()
{
char month[100],l[3];
scanf("%s",month);
scanf("%s",l);
if((strcmp(l,"22")==0) && (strcmp(month,"Sep")==0))
printf("Fall");
if((strcmp(l,"20")==0) && (strcmp(month,"Mar")==0))
printf("Summer");
if((strcmp(l,"21")==0) && (strcmp(month,"Jun")==0))
printf("Spring");
if((strcmp(l,"21")==0) && (strcmp(month,"Dec")==0))
printf("Winter");
return 0;
}
Test Case 1
Input (stdin)Sep 22
Expected OutputFall
Test Case 2
Input (stdin)Mar 20
Expected OutputSummer
This blog is to help for the programmers to learn the programs and not to demotivate any people .Our intention is to make the learners to learn the code easily.Next UPDATE (TODAY 2pm).For further updates follow us.Comment your doubts we'll help you as soon as possible..
Sunday, September 23, 2018
Saturday, September 22, 2018
game
Problem Description
" You are playing following game: given an array A of N natural numbers. All numbers in the array A are at most M. On every turn you may pick any two different elements Ai and Aj (ij), such that Ai, Aj M, and add K to both. The game ends when you are not able to continue. That is, when there is no pair (i,j) left such that both of them are less than equal to M.
Let's call two arrays different if the sum of all their elements is different. When the game ends, you note down the final array A. How many different final arrays can you have.
Input
The first line contains three integers N, M and K. N elements of the array follow in the next line.
Constraints
1 <= N <= 1000000
1 <= M,K<= 10000000000000
1 <= Ai <= M
test case 1:All possible sums are 14 and 10. You can get them by, for example, these arrays:
A=(5, 4, 5),
A=(1, 4, 5)
The above arrays are different because their sums are different."CODING ARENA
#include<stdio.h>
int N;
long long M,K;
long long A[100000];
int main()
{
int i;
long long sum=0;
long long max=0;
scanf("%d %lld %lld",&N,&M,&K);
for(i=0;i<N;i++)
{
scanf("%lld",&A[i]);
A[i]=(M-A[i])/K+1;
if(max<A[i])
max=A[i];
sum+=A[i];
}
long long min=0;
if((sum-max)%2==0)
min=(sum-max)/2;
else
min=(sum-max)/2+1;
long long ans=sum/2-min+1;
ans=ans%(1000000007);
printf("%lld\n",ans);
return 0;
}
Test Case 1
Input (stdin)3 3 2 1 2 3
Expected Output2
Test Case 2
Input (stdin)3 3 3 2 2 2
Expected Output1
Sum of Even numbers
Problem Description
Write a program to find the sum of even numbers in an array.
Input Format:
Input consists of n+1 integers. The first integer corresponds to n, the size of the array. The next n integers correspond to the elements in the array. Assume that the maximum value of n is 15.
Output Format:
Refer sample output for details.CODING ARENA
#include <stdio.h>
int main()
{
int n,a[10],i,s=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
s=s+a[i];
}
}
printf("The sum of the even numbers in the array is:%d",s);
return 0;
}
Test Case 1
Input (stdin)5 2 3 6 8 -1
Expected OutputThe sum of the even numbers in the array is:16
Test Case 2
Input (stdin)7 2 3 4 2 3 4 1
Expected OutputThe sum of the even numbers in the array is:12
Hexadecimal's Numbers
Problem Description
"One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy.
But his plan failed. The reason for this was very simple: Hexadecimal didn't perceive any information, apart from numbers written in binary format. This means that if a number in a decimal representation contained characters apart from 0 and 1, it was not stored in the memory. Now Megabyte wants to know, how many numbers were loaded successfully.
Input
Input data contains the only number n (1<n<109).
Output
Output the only number answer to the problem.
"CODING ARENA
#include<stdio.h>
int tot=0;
void getNum(long long num,long long n)
{
if(num>n)
return;
tot++;
num=num*10;
getNum(num+1,n);
getNum(num,n);
}
int main()
{
long long n;
scanf("%lld",&n);
getNum(1,n);
printf("%d",tot);
return 0;
}
Test Case 1
Input (stdin)10
Expected Output2
Test Case 2
Input (stdin)20
Expected Output3
Nth FIBO
Problem Description
John played with jacob.John wanted to test how soon jacob will answer for his question.He told him one number.The job of john is to add the numbers 0 and 1 initially and to add that output with 1.Now Jacob gets another output.jacob has to add this current output with previous output .This action has to be repeated upto certain times.After this Jacob needs to write those outputs as a series starts from 0,1 and to find out the n th number of that series what john told.Write a code for this.CODING ARENA
#include <stdio.h>
int fibo(int);
int main()
{
int num;
int result;
scanf("%d", &num);
if (num < 0)
{
}
else
{
result = fibo(num);
printf("%d\n",result);
}
return 0;
}
int fibo(int num)
{
if (num == 0)
{
return 0;
}
else if (num == 1)
{
return 1;
}
else
{
return(fibo(num - 1) + fibo(num - 2));
}
}
Test Case 1
Input (stdin)8
Expected Output21
Test Case 2
Input (stdin)12
Expected Output144
Non-empty subset
Problem Description
Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0.
Input
The first line of input contains T - number of test cases.
Each of the next T lines containing four pairwise distinct integer numbers - a, b, c, d.
Output
For each test case output ""Yes"", if possible to get 0 by choosing non-empty subset of {a, b, c, d} with sum equal 0, or ""No"" in another case.CODING ARENA
#include <stdio.h>
int main()
{
int a,b[100],i,j,d=0;
scanf("%d",&a);
for(i=0;i<a;i++)
{
for(j=0;j<4;j++)
scanf("%d",&b[j]);
if(b[0]==0||b[1]==0||b[2]==0||b[3]==0)
d=d+1;
else if(b[0]==-b[1]||b[0]==-b[2]||b[0]==-b[3]||b[1]==-b[2]||b[1]==-b[3]||b[2]==-b[3])
d=d+1;
else
d=0;
if(d>0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
Test Case 1
Input (stdin)3 1 2 0 3 1 2 4 -1 1 2 3 4
Expected OutputYes Yes No
Test Case 2
Input (stdin)2 2 4 5 1 2 2 3 2
Expected OutputNo No
Array Mean
Problem Description
Write a program to find the mean of the elements in the array.
Input and Output Format:
Input consists of n+1 integers where n corresponds to the number of elements in the array.
The first integer corresponds to n and the next n integers correspond to the elements in the array.
Output consists of a double value which corresponds to the mean of the array. It is printed upto 2 digits of precision.
Assume that the maximum number of elements in the array is 20.
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.CODING ARENA
#include <stdio.h>
int main()
{
int i;
float a,b[100],c=0;
scanf("%f",&a);
for(i=0;i<a;i++)
{
scanf("%f",&b[i]);
c=c+b[i];
}
printf("The mean of the array is %.2f",c/a);
return 0;
}
Test Case 1
Input (stdin)5 2 4 1 3 5
Expected OutputThe mean of the array is 3.00
Test Case 2
Input (stdin)10 100 105 200 205 108 15 18 88 1000 12
Expected OutputThe mean of the array is 185.10
Simple Array
Problem Description
Calculate average of n numbersCODING ARENA
#include<stdio.h>
int main()
{
int a,b[100],c=0,i;
scanf("%d",&a);
for(i=0;i<a;i++)
{
scanf("%d",&b[i]);
c=c+b[i];
}
printf("%d",c/a);
return 0;
}
Test Case 1
Input (stdin)5 1 2 3 4 5
Expected Output3
Test Case 2
Input (stdin)3 1 2 3
Expected Output2
PRINT 1
Problem Description
Write a C program to print all numbers between a and b ( a and b inclusive) using a for loop.
Input format:
Input consists of 2 integers. The first integer corresponds to a and the second integer corresponds to b . Assume a>=b.
Output format:
Refer sample input and output for formatting specifications.CODING ARENA
#include<stdio.h>
int main()
{
int a,b,i;
scanf("%d%d",&a,&b);
for(i=a;i<=b;i++)
printf("%d\n",i);
return 0;
}
Test Case 1
Input (stdin)4 10
Expected Output4 5 6 7 8 9 10
Test Case 2
Input (stdin)-1 6
Expected Output-1 0 1 2 3 4 5 6
Subscribe to:
Posts (Atom)