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

Sunday, December 15, 2013

DCRYPT - Decrypt the message !

Decrypt the message !

dcrypt spoj solution or decrypt the message spoj solution

dcrypt spoj solution or decrypt the message spoj solution
 

#include<stdio.h>
#include<stdlib.h>
int main()
{
 int TIME;
 scanf("%d",&TIME);
 while(TIME--)
 {
  int key;
  scanf("%d",&key);
  char *ENC,temp,ch;
  ENC=(char *)malloc(100001*sizeof(char));
  scanf("%s",ENC);
  int i=0;
  if(key<=25)
  {
   while(ENC[i]!=0)
   {
    ch=ENC[i];
    if(ch>=97&&ch<=122)
    {
     ch=ch-97;
     ch=(ch+key)%26;
     ch=ch+97;
    }
    else if(ch>=65&&ch<=90)
    {
     ch=ch-65;
     ch=(ch+key)%26;
     ch+=65;
    }
    else
     ch=32;
    ENC[i]=ch;
    i++;
   }
  }
  else
  {
   while(ENC[i]!=0)
   {
    ch=ENC[i];
    if(ch>=97&&ch<=122)
    {
     ch=ch-97;
     ch=(ch+key)%26;
     ch=ch+65;
    }
    else if(ch>=65&&ch<=90)
    {
     ch=ch-65;
     ch=(ch+key)%26;
     ch+=97;
    }
    else
     ch=32;
    ENC[i]=ch;
    i++;
   }
  }
  printf("%s\n",ENC);
 }
 return 0;
}


2 comments:

Your comment is valuable to us