Saturday, July 15, 2017

URI problem 1024 solution in C | (Encryption)

#include<stdio.h>
#include<string.h>

int main()
{
    int i,j,k=3,l,n,o,p;
    char ch[1002],ch1[1002];
    scanf("%d",&n);
    getchar();
    for(i = 0;i < n;i++){
        gets(ch);
        l = strlen(ch);
        for(j=0;j<l;j++){
            if((ch[j]>='A' && ch[j]<='Z') || (ch[j]>='a' && ch[j]<='z'))ch[j] += 3;
        }
        p=l-1;
        for(j=0;j<l;j++){
            ch1[j]=ch[p];
            p--;
        }
        ch1[j]='\0';
        for(j = l/2;j < l;j++)
            ch1[j] -= 1;
        printf("%s\n",ch1);
    }
    return 0;
}

3 comments:

  1. ch1[j]='\0' eita ki bujhai vai?? ekhane j er default value to 0. taile ch1[0]= string er sesh bujhai na??

    ReplyDelete
    Replies
    1. Null='0'
      Nul='\0'
      Nul('\0') is an ascii character and its ascii value is 0. '\0' represent the end of an string in c programming language.

      Delete
  2. assalamu alaikum sir...why you assumed k=3??

    ReplyDelete