日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Progressive Scramble

發布時間:2023/12/8 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Progressive Scramble 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

You are a member of a naive spy agency. For secure communication,members of the agency use a very simple encryption algorithm – which changes each symbol in the message ‘progressively’, i.e., based on the symbols preceding it. The allowed symbols are space and the 26 lowercase English letters. For encryption purposes we assign them the values 0 (for space) and 1 through 26 (for a–z). We’ll let v(s) represent the numeric value of symbol s.
Consider a message with symbols s1, s2, . . . , sn. The encryption algorithm starts by converting the ?rst symbol s1 into its associated value u1?= v(s1). Then for each subsequent symbol si?in the message, the computed value is ui?= v(si) + ui?1?— the sum of its associated value and the computed value for the previous symbol. (Note that when there is a space in the input
message, the previous scrambled letter is repeated.) This process continues until all the ui are computed.
At this point, the message is a sequence of numeric values. We need to convert it back to symbols to print it out. We do this by taking the value uimodulo 27 (since there are 27 valid symbols), and replacing that value with its corresponding symbol. For example, if ui?= 32, then 32 mod 27 = 5, which is the symbol ‘e’ (since v(e) = 5).
Let’s look at an example. Suppose we want to encrypt the string “my pie”.?
1. First, convert each symbol si?into v(si): [13, 25, 0, 16, 9, 5].
2. Next, compute each ui: [13, 38, 38, 54, 63, 68].
3. Then, use modulus on the ui: [13, 11, 11, 0, 9, 14].
4. Finally, convert these back to symbols: “mkk in”.
Create a program that takes text and encrypts it using this algorithm, and also decrypts text that has been encrypted with this algorithm.
?

輸入

The input to your program consists of a single integer 1 ≤ n ≤ 100 on its own line. This number is followed by n lines, each containing the letter ‘e’ or ‘d’, a single space, and then a message made up of lowercase letters (a–z) and spaces, continuing to the end of the line. Each message is between 1 and 80 characters long. The letters ‘d’ and ‘e’ indicate that your program decrypts or encrypts the subsequent string, respectively.

?

輸出

Output the result of encrypting or decrypting each message from the input on its own separate line. Note that differences in whitespace are significant in this problem. Therefore your output must match the correct output character-for-character, including spaces.

#include<iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <map> #include<deque> #include<cmath> #define ll long long # define inf 0x3f3f3f3f using namespace std; char ch,str[1008611]; ll ans[1008611],len,tmp[1008611],num[1008611]; void jia(){for(int i=0;i<len;i++){if(str[i]==' ')ans[i]=0;else ans[i]=str[i]-'a'+1;}for(int i=1;i<len;i++){ans[i]+=ans[i-1];}for(int i=0;i<len;i++){ans[i]%=27;}for(int i=0;i<len;i++){if(ans[i]==0)str[i]=' ';else str[i]=ans[i]+'a'-1;} } ll flag=0; void jie(){for(int i=0;i<len;i++){if(str[i]==' ')ans[i]=0;else ans[i]=str[i]-'a'+1;}for(int i=1;i<len;i++){num[i]=num[i-1] +ans[i-1];while(ans[i]<num[i])ans[i] += 27;ans[i] = (ans[i] - num[i]) % 27;}for(int i=0;i<len;i++){if(ans[i]==0)str[i]=' ';else str[i]=ans[i]+'a'-1;}} int main(){ll t;scanf("%lld",&t);getchar();while(t--){scanf("%c",&ch);getchar();gets(str);//puts(str);len=strlen(str);if(ch=='e'){jia();}else{jie();}for(int i=0;i<len;i++){printf("%c",str[i]);}printf("\n");}return 0; }

?

總結

以上是生活随笔為你收集整理的Progressive Scramble的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。