Posts

Find Product ! Hacker Earth

You have been given an array  A A  of size  N N  consisting of positive integers. You need to find and print the product of all the number in this array  Modulo   10 9 + 7 10 9 + 7 . Input Format : The first line contains a single integer  N N  denoting the size of the array. The next line contains  N N  space separated integers denoting the elements of the array Output Format : Print a single integer denoting the product of all the elements of the array Modulo  10 9 + 7 10 9 + 7 . Constraints : 1 ≤ N ≤ 10 3 1 ≤ N ≤ 10 3 1 ≤ A [ i ] ≤ 10 3 Source Code in C: #include <stdio.h> int main() { unsigned N, i, answer = 1; do { scanf("%d", &N); } while(N < 1 && N > 1000); long int a[N]; for(i = 0; i < N ; i++) { do { scanf("%li", &a[i]); } while(a[i] < 1 && a[i] ...

Seating Arrangement

Image
Akash  and  Vishal  are quite fond of travelling. They mostly travel by railways. They were travelling in a train one day and they got interested in the seating arrangement of their compartment. The compartment looked something like So they got interested to know the seat number facing them and the seat type facing them. The seats are denoted as follows :  Window Seat :  WS Middle Seat :  MS Aisle Seat :  AS You will be given a seat number, find out the seat number facing you and the seat type, i.e.  WS ,  MS  or  AS . INPUT First line of input will consist of a single integer  T  denoting number of test-cases. Each test-case consists of a single integer  N  denoting the seat-number. OUTPUT For each test case, print the facing seat-number and the seat-type, separated by a single space in a new line. CONSTRAINTS 1<= T <=10 5 1<= N <=108 Source Code in C: #include<stdio.h...

Life, the Universe, and Everything ! Hacker Earth

Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits. Source Code in C: #include <stdio.h> int main() { int no; while(1) { scanf("%d", &no); if(no==42) break; else printf("%d\n",no); } return 0; } SAMPLE INPUT 1 2 88 42 99 SAMPLE OUTPUT 1 2 88

Magical Word ! Hacker Earth

Dhananjay has recently learned about  ASCII  values.He is very fond of experimenting. With his knowledge of  ASCII  values and character he has developed a special word and named it Dhananjay's Magical word. A word which consist of alphabets whose  ASCII  values is a prime number is an Dhananjay's Magical word. An alphabet is Dhananjay's Magical alphabet if its  ASCII  value is prime. Dhananjay's nature is to boast about the things he know or have learnt about. So just to defame his friends he gives few string to his friends and ask them to convert it to Dhananjay's Magical word. None of his friends would like to get insulted. Help them to convert the given strings to Dhananjay's Magical Word. Rules for converting: 1.Each character should be replaced by the nearest Dhananjay's Magical alphabet. 2.If the character is equidistant with 2 Magical alphabets. The one with lower  ASCII  value will be considered as its replacement. ...

Factorial !

You have been given a positive integer  N N . You need to find and print the  Factorial  of this number. The Factorial of a positive integer  N N  refers to the product of all number in the range from  1 1  to  N N . You can read more about the factorial of a number  here. Input Format : The first and only line of the input contains a single integer  N N  denoting the number whose factorial you need to find. Output Format Output a single line denoting the factorial of the number  N N . Constraints 1 ≤ N ≤ 10 Source code in C: #include<stdio.h> int main() { int N,i,fact; fact=1; scanf("%d",&N); for(i=1;i<=N;i++) { fact=fact*i; } printf("%d",fact); return 0; }

Prime Number

You are given an integer N. You need to print the series of all prime numbers till N. Input Format The first and only line of the input contains a single integer N denoting the number till where you need to find the series of prime number. Output Format Print the desired output in single line separated by spaces. Constraints 1<=N<=1000 Source Code: #include <stdio.h> int main() { int n,flag,i,j; scanf("%d",&n); printf("2 "); for(i=3;i<=n;i=i+2) { flag=0; for(j=3;j<=i/2;j++) { if(i%j==0){ flag=1;break;} } if(flag==0){printf("%d ",i);} } }

Roy and Profile picture

Roy wants to change his profile picture on Facebook. Now Facebook has some restriction over the dimension of picture that we can upload. Minimum dimension of the picture can be  L x L , where  L  is the length of the side of square. Now Roy has  N  photos of various dimensions. Dimension of a photo is denoted as  W x H where  W  - width of the photo and  H  - Height of the photo When any photo is uploaded following events may occur: [1] If any of the width or height is less than L, user is prompted to upload another one. Print " UPLOAD ANOTHER " in this case. [2] If width and height, both are large enough and (a) if the photo is already square then it is accepted. Print " ACCEPTED " in this case. (b) else user is prompted to crop it. Print " CROP IT " in this case. (quotes are only for clarification) Given L, N, W and H as input, print appropriate text as output. Input: First line contains  L . Second ...