<> In the process of transmitting information , For encryption , Sometimes it is necessary to convert text into ciphertext and send it out according to certain rules . There is an encryption rule like this :

1. For alphabetic characters , Convert it to the next 3 Two letters . for example :A→D,a→d,X→A,x→a;
2. For non alphabetic characters , remain unchanged .
Now? , Please input a line of characters according to the input , Output the corresponding password .

input :I(2016)love(08)China(15)!
output :L(2016)oryh(08)Fklqd(15)!

be careful : String length not more than 100.

This is a topic about circulation
This topic is how to transform the last three characters , But if you choose to use if Statement to deal with the last three , You can close this blog . okay

The following is a circular method to realize the transformation .
Take capital letters as an example .
A,B,C,D,E,F,G,H…X,Y,Z.
So that's how to turn back the last three characters ?

<> The first step is to change

What about my words , The first step is to make it a circle , Not a row ,
So there's one 26 A circle of two letters .

<> The second step is to find the rules

A---->D namely ‘A’+3
B---->F namely ‘A’+(‘B’-‘A’+3)
C---->G namely ‘A’+(‘C’-‘A’+3)
.
.
.
X---->A namely ‘A’+(‘X’-‘A’+3) It's not working here .
Just find a way to turn it back , Then make it a circle , We can take advantage of a surplus to loop .
It becomes the following form :
‘A’+(‘X’-‘A’+3)%26
We can solve the problem of moving forward all the way .

Maybe you feel a little confused , Why can this circle ?!
for instance :
1,2,3,4,5 Five numbers
Then there is
1%5=1,
2%5=2,
3%5=3,
4%5=4,
5%5=0,
6%5=1,
7%5=2,
See , Just make an analogy , Take the remainder as many as you have .
Attach complete code :
#include <stdio.h> #include <string.h> int main() { int i,j,k; char a[100],b[
100]; gets(a); for(i=0;i<strlen(a);i++) { if (a[i]>='A' && a[i]<='Z') { a[i]='A'
+(a[i]-'A'+3)%26; } else if (a[i]>='a' && a[i]<='z') { a[i]='a'+(a[i]-'a'+3)%26;
} } for (j=0;j<strlen(a);j++) { printf("%c",a[j]); } return 0; }
If you have a better solution , You can also leave a message , Learn from each other .

Technology