Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com
And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Thursday, January 30, 2014

RLCIPHER-Robert Langdon & Cipher

Robert Langdon & Cipher

below given code is for rlcipher spoj or robert langdon & cipher spoj.
logic behind this problem is simple .as number greater then 6 can be expressed in form of multiple of 3 and 4.
let n > 6 then
n = p * 3 + q * 4; > 0 ,0
eg  :                 14 = 2*3 + 2*4.
#include<stdio.h>
int main()
{
 int t;
 scanf("%d",&t);
 int result[7]={-4,-3,-2,-4,-4,-3,-4};
 while(t--)
 {
  long N;
  scanf("%ld",&N);
  int i;
  long temp;
  for(i=0;i<N;i++){
   scanf("%ld",&temp);
   if(temp>=0)
   {
    if(temp>6)
     printf("-4 ");
    else
     printf("%d ",result[temp]);
   }
   else
    printf("%ld ",temp);
  }
  printf("\n");
 }
 return 0;
}