GOC 102 "Crime Investigation" - Editorial

PROBLEM LINK:

https://www.codechef.com/problems/GOC102
https://www.codechef.com/GMCD2016/problems/GOC102

Author: https://www.codechef.com/users/nilesh_dbit
Tester: https://www.codechef.com/users/nilesh_dbit
Editorialist: https://www.codechef.com/users/nilesh_dbit

DIFFICULTY:

EASY-MEDIUM

PROBLEM:

Crime Scene: Two undercover ATS officer investigating bomb explosion case & its terror link in Mumbai and they both were found murdered .They were about to solve the case and collect evidences against a business man for funding the terror activities. There was a complete mistrust among the Detective Inspector Daya Nayak and his team as someone was leaking the information. Department of Home Affairs decided to appoint Mr.Sherlock to help Mr. Daya solve the case but warned not to trust anyone. Mr. Sherlock was assisted by Dr.Watson. They both want a mechanism to communicate with each other keep communication hidden from others. The mechanism say that you should reverse each character of the word and then replace each character to the right by 3.

EXPLANATION:

Example:
Input : i love india
i evol aidni
Output: l#hyro#dlgql

AUTHOR’S AND TESTER’S SOLUTIONS:


#include<stdio.h> 
/*Function to reverse any sequence starting with pointer begin and ending with pointer end */ 
void reverse(char *begin, char *end) 
{ 
char temp; 
while (begin < end) 
{ 
	temp = *begin; 
	*begin++ = *end; 
	*end-- = temp; 
} 
} 
 void encode(char *s) 
{ 
    while(*s) 
    { 
       // printf("B-->%c   ",*s); 
        *s=*s+3; 
       // printf("A-->%c \n",*s); 
        s++; 
    } 
} 


void reverseWords(char *s) 
{ 
    char *word_begin = NULL; 
    char *temp = s; /* temp is for word boundry */ 
 
    /*STEP 1 of the above algorithm */ 
    while( *temp ) 
    { 
        /*This condition is to make sure that the string start with 
          valid character (not space) only*/ 
        if (( word_begin == NULL ) && (*temp != ' ') ) 
        { 
            word_begin=temp; 
        } 
        if(word_begin && ((*(temp+1) == ' ') || (*(temp+1) == '\0'))) 
        { 
            reverse(word_begin, temp); 
            word_begin = NULL; 
        } 
        temp++; 
    } /* End of while */ 
 
   
} 
 
/* Driver function to test above functions */ 
int main() 
{ 
char s[100]; // = "i like this program very much"; 
fgets(s,100,stdin); 
//printf("%s\n", s); 

reverseWords(s); 
encode(s); 
printf("%s\n", s); 
getchar(); 
return 0; 
} 

//