「CFgym100486C」Text Encryption
To keep privacy of messages and prevent the aliens from reading them, we may use various
encryption algorithms. These algorithms encode a message into the so-called ciphertext that is
difficult (or impossible) to decode for anyone else than the intended recipient. Transposition
ciphers are a type of encryption that do not change the letters of the message but only change
their order (“shuffle” the letters). Of course, the shuffling must be reversible to allow later
decryption.
In this problem, we will consider a simple transposition cipher which shuffles the letters in
such a way that the decryption algorithm always takes every n-th letter. More specifically:
when decrypting, the first letter of the ciphertext is taken first, then the next n − 1 letters are
(repeatedly) skipped and the next letter taken, and so on until we reach the end of the ciphertext.
After that, we repeat the procedure starting with the second letter of the ciphertext, and so on
until all letters are used.
Your task is to implement the encryption algorithm for this cipher. For a given message, produce
the encrypted text (ciphertext). To make the cipher a little bit stronger, you should convert all
letters to uppercase and leave out all spaces between words.
Input Specification
The input contains several messages. Each message is described by two lines. The first line
contains one integer number N (1 ≤ N ≤ 1000). The second line contains the message. The
message will be at most 10 000 characters long, it will only contain letters and spaces, and there
will be at least one letter in each message.
The last message is followed by a line containing zero.
Output Specification
For each message, output the ciphertext that, after using the described decryption algorithm,
will result in the original message (with all spaces removed and all letters in uppercase).
Sample Input
2
CTU Open Programming Contest
7
This is a secret message that noone should ever see Lets encrypt it
15
text too short
0
Output for Sample Input
CMTMUIONPGECNOPNRTOEGSRTA
TESNUECHCAOLERIRGODLYSEENEEPITTEVTTSMHSESIAEAHRETSSTOSN
TEXTTOOSHORT
题解
模拟
看题面的时间比写题长多了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #define inf 1000000000 #define ll long long using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } char ch[10005],ans[10005]; int n,tot,next; bool vis[10005]; int main() { n=read(); while(1) { memset(vis,0,sizeof(vis)); tot=1;next=0; while(scanf("%s",ch+tot)) { int len=strlen(ch+tot); if(ch[tot]>='0'&&ch[tot]<='9') { for(int i=tot;i<tot+len;i++) next=next*10+ch[i]-'0'; break; } tot+=len; } tot--; int now=1,tmp=1; for(int i=1;i<=tot;) if(!vis[tmp]) { vis[tmp]=1;ans[tmp]=ch[i];tmp+=n; if(tmp>tot)tmp=now=now+1; i++; } for(int i=1;i<=tot;i++) if(ans[i]>='a'&&ans[i]<='z')printf("%c",ans[i]-'a'+'A'); else printf("%c",ans[i]); printf("\n"); if(next)n=next; else break; } return 0; } |
relogios masculinos rolex
Você pode distrair-se por ouvir música calma, assistindo a um filme otimista, ler um bom livro, jogar um jogo ou entregando-se a um jogo de palavras cruzadas.