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

Saturday, March 1, 2014

SNGMSG - Encode Message

Encode Message

given below code is for sngmsg spoj or Encode Message spoj.
easy one no need of explanation .
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
using namespace std;
int main()
{
   int t;
   scanf("%d ",&t);
   while(t--)
   {
      char s[600],num[10],result[600],enc[50];
      gets(num);
      gets(s);
      int len_num=strlen(num),i=0,count,j=0,k=0,l;
      l=len_num-1;
      k=len_num;
      while(num[i]!='\0')
      {
         enc[j++]=num[i++];
         enc[k++]=num[l--];
      }
      enc[k]='\0';
      i=0;k=0;count=0;
      while(s[i]!='\0')
      {
         if(count>(2*len_num - 1))
            count=0;
         j=s[i]-(enc[count]-48);
         if(j<97)
            result[k++]=26+j;
         else
            result[k++]=j;
         i++;
         count++;
      }
      result[k]='\0';
      printf("%s\n",result);
   }
   return 0;
}

No comments:

Post a Comment

Your comment is valuable to us