Size Contest (SPOJ Challenge problem 378)

Given the set of integers, find the sum of all positive integers in it. Solutions can be sent in any language supported by SPOJ except Whitespace.


t – number of test cases [t < 1000]
On each of next t lines given a integer N [-1000 <= N <= 1000]


One integer equals to sum of all positive integers.


Score equals to size of source code of your program except symbols with ASCII code <= 32.


C Program :


Factorial (SPOJ problem 11)

View problem on SPOJ

The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a little simplified view). Of course, BTSes need some attention and technicians need to check their function periodically.

ACM technicians faced a very interesting problem recently. Given a set of BTSes to visit, they needed to find the shortest path to visit all of the given points and return back to the central company building. Programmers have spent several months studying this problem but with no results. They were unable to find the solution fast enough. After a long time, one of the programmers found this problem in a conference article. Unfortunately, he found that the problem is so called “Travelling Salesman Problem” and it is very hard to solve. If we have N BTSes to be visited, we can visit them in any order, giving us N! possibilities to examine. The function expressing that number is called factorial and can be computed as a product….N. The number is very high even for a relatively small N.

The programmers understood they had no chance to solve the problem. But because they have already received the research grant from the government, they needed to continue with their studies and produce at least some results. So they started to study behaviour of the factorial function.

For example, they defined the function Z. For any positive integer NZ(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbersN1<N2, then Z(N1) <= Z(N2). It is because we can never “lose” any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently.


There is a single positive integer T on the first line of input (equal to about 100000). It stands for the number of numbers to follow. Then there are T lines, each containing exactly one positive integer number N, 1 <= N<= 1000000000.


For every number N, output a single line containing the single non-negative integer Z(N).


Sample Input:

Sample Output:




Check whether one string is rotated version of other(Josh software programming test problem-2)

Write a program to accept two strings str1 and str2 and checks whether str2 is rotated version of str1.
Ex. Following are different values of str2 for given str1.
2-character left rotate
4-character left rotate
3-character right rotate

It seems to be bit difficult problem ,but it’s not actually. To solve this problem , We have to append first string to itself. And then check whether second string is present in first or not.

For example:
so append str1 to itself. Hence now str1=”softwaresoftware” . Now check str2 is present in str1 or not. Str2 is present in str1, hence str2 is rotated version of str1.

Note- You can not use strcat() function of string.h to concatenate a string to itself .Concatenation of string to itself using strcat() function is undefined behavior in C.

Solution using inbuilt  function of C.


Solution without using inbuilt functions

Josh Software programming test Problem 1

Leave comment if you have any problem with code.

Generate graph from input 1-D array (Josh Software programming test problem-1)

Following program was asked by Josh Software during campus recruitment.
Write a program to generate following chart without using any graph library.This is of marks from 1 to 5 obtained by 10 student represented by an array as [2,4,5,1,2,4,1,1,5,2]
Y axis denote marks and X axis denotes student role number.

Josh software apti program

Variation of problem:
Write a program to generate graph (Roll number Vs marks obtained) without using any graph library. Accept marks of n student from user, represented by an array . Y axis denote marks and X axis denotes student role number.

If you have any problem with code,please comment below.

Remove duplicate characters in string

Write code to remove the duplicate characters in a string
without using any additional buffer NOTE: One or two additional variables are fine
An extra copy of the array is not.
This question is from the book “cracking thecoding interview”.

Time complexity= O(n^2)

Leave comment if you have any problem with code.
Recursive insertion sort

Recursive insertion sort


Snake game in C language using queue

Requirments: Turbo C++ compiler

If you face any graphics error ,follow these steps.

  1. Go to “BGI” folder. ( C:\TurboC++\Disk\TurboC3\BGI).
  2. Copy file “EGAVGA.BGI” 
  3. Got “BIN” folder. ( C:\TurboC++\Disk\TurboC3\BIN).
  4. Paste “EGAVGA.BGI” file .
  5. Close Turbo C++ and open it again and run program.

How snake game works?:

  1. Initialize the snake by inserting 4 nodes in queue
  2. Print the queue, these 4 nodes will create snake
  3. To move the snake, add new node in front of head and delete node from tail
  4. clear screen and redraw the screen
  5. This will create illusion of moving snake
  6. If snake hits the food then add extra node in queue
  7. if snake hits the wall or himself then end the game

Download .C file-> SNAKE ( Right click & Save link As). Copy paste code on your local machine