URI Online Judge Solution 1024 Encryption using C Programming Language.
You have been asked to build a simple encryption program. This program should be able to send coded messages without someone been able to read them. The process is very simple. It is divided into two parts.First, each uppercase or lowercase letter must be shifted three positions to the right, according to the ASCII table: letter 'a' should become letter 'd', letter 'y' must become the character '|' and so on. Second, each line must be reversed. After being reversed, all characters from the half on (truncated) must be moved one position to the left in ASCII. In this case, 'b' becomes 'a' and 'a' becomes '`'.
For example, if the resulting word of the first part is "tesla", the letters "sla" should be moved one position to the left. However, if the resulting word of the first part is "t#$A", the letters "$A" are to be displaced.
Input
The input contains a number of cases of test. The first line of each case of test contains an integer N (1 ≤ N ≤ 1 * 10⁴), indicating the number of lines the problem should encrypt. The following N lines contain M characters each M (1 ≤ M ≤ 1 * 10³).
Output
For each input, you must present the encrypted message.
Input Sample | Output Sample |
4
Texto #3 abcABC1 vxpdylY .ph vv.xwfxo.fd |
3# rvzgV
1FECedc ks. \n{frzx gi.r{hyz-xx |
Solution :
#include <stdio.h>
#include <string.h>
int main()
{
char str[1000],str1[1000];
int i,k,j,n,m,l,T;
scanf("%d",&T);
getchar();
while(T--)
{
gets(str);
k = strlen(str);
for(i=0;i<k;i++)
{
if((str[i]>='A' && str[i]<='Z') || (str[i]>='a'&& str[i]<='z'))
str[i] = str[i] + 3;
}
n=0;
for(j=k-1;j>=0;j--)
{
str1[n] = str[j];
n++;
}
str1[n] = '\0';
l = k/2;
for(i=l;i<k;i++)
{
str1[i] = str1[i] - 1;
}
printf("%s\n",str1);
}
return 0;
Comments
Post a Comment