1006 do the untwist

Source: Internet
Author: User

Evaluate the knowledge of programming and convert characters and numbers. The format is to describe the conversion rules of plain text and dark text.

 1 #include <stdio.h> 2 #include <string.h> 3  4 #define MAXLEN 71 5  6 int length; 7  8 void toCode(int code[],char text[]){ 9     int i;10     for(i=0;i<length;i++){11         if(text[i] == ‘_‘)12             code[i] = 0;13         else if(text[i] == ‘.‘)14                 code[i] = 27;15             else16                 code[i] = text[i] - 96;17     }18 }19 20 void toText(char text[],int code[]){21     int i;22     for(i=0;i<length;i++){23         if(code[i] == 0)24             text[i] = ‘_‘;25         else if(code[i] == 27)26                 text[i] = ‘.‘;27             else28                 text[i] = code[i] + 96;29     }30     text[i] = 0;31 }32 33 int inRange(int n){34     if(n>=0&&n<=27)35         return 1;36     return 0;37 }38 39 void untwist(char textC[],int k){40     int i,j;41     int codeC[MAXLEN],codeP[MAXLEN];42     char textP[MAXLEN];43 44     toCode(codeC,textC);45     for(i=0;i<length;i++){46         j = (k*i)%length;47         if(inRange(codeC[i] + i)) 48             codeP[j] = codeC[i] + i;49         else if(inRange(codeC[i] + i - 28)) 50                 codeP[j] = codeC[i] + i - 28;51             else if(inRange(codeC[i] + i - 56)) 52                     codeP[j] = codeC[i] + i - 56;53                 else if(inRange(codeC[i] + i - 84)) 54                         codeP[j] = codeC[i] + i - 84;55     }56     toText(textP,codeP);57     printf("%s\n",textP);58 }59 60 int main(){61     int k;62     char textC[MAXLEN];63     while(scanf("%d",&k)&&k){64         scanf("%s",textC);65         length = strlen(textC);66         untwist(textC,k);67     }68     return 0;69 }

1006 do the untwist

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.