zoukankan      html  css  js  c++  java
  • Codeforces Round #528-A. Right-Left Cipher(字符串模拟)

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Polycarp loves ciphers. He has invented his own cipher called Right-Left.

    Right-Left cipher is used for strings. To encrypt the string s=s1s2…sns=s1s2…sn Polycarp uses the following algorithm:

    • he writes down s1s1,
    • he appends the current word with s2s2 (i.e. writes down s2s2 to the right of the current result),
    • he prepends the current word with s3s3 (i.e. writes down s3s3 to the left of the current result),
    • he appends the current word with s4s4 (i.e. writes down s4s4 to the right of the current result),
    • he prepends the current word with s5s5 (i.e. writes down s5s5 to the left of the current result),
    • and so on for each position until the end of ss.

    For example, if ss="techno" the process is: "t" →→ "te" →→ "cte" →→ "cteh" →→ "ncteh" →→ "ncteho". So the encrypted ss="techno" is "ncteho".

    Given string tt — the result of encryption of some string ss. Your task is to decrypt it, i.e. find the string ss.

    Input

    The only line of the input contains tt — the result of encryption of some string ss. It contains only lowercase Latin letters. The length of tt is between 11 and 5050, inclusive.

    Output

    Print such string ss that after encryption it equals tt.

    Examples

    input

    Copy

    ncteho
    

    output

    Copy

    techno
    

    input

    Copy

    erfdcoeocs
    

    output

    Copy

    codeforces

    input

    Copy

    z
    

    output

    Copy

    z

    分一下字符串的奇偶模拟即可,注意要用char 不要用string

    代码:

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    
    using namespace std;
    
    int main() {
    
    	char str[10005],str1[10005];
    	scanf("%s",str);
    	int len=strlen(str);
    	int s=0;
    	if(len%2==0) {
    
    		for(int t=len/2-1; t>=0; t--) {
    			str1[s++]=str[t];
    			str1[s++]=str[len-1-t];
    		}
    	} else {
    		str1[s++]=str[len/2];
    		for(int t=len/2-1; t>=0; t--) {
    			str1[s++]=str[len-1-t];
    			str1[s++]=str[t];
    		}
    	}
    	for(int t=0; t<s; t++) {
    		cout<<str1[t];
    	}
    	return 0;
    }
  • 相关阅读:
    10.13_extjs,combox,效率为什么这么低
    10.12_win8风格,把专业书籍当小说看,SQLite
    10.11_魔兽世界
    10.10_魔兽账号,OSC代码托管演示,研究SQL别忘记了,git
    10.09_命名:包名、类名、方法名
    10.08_逛逛OSC
    国庆第七日(2014年10月7日17:55:56),随手记,一些关注的OSC软件,花生壳
    国庆第六日(2014年10月6日11:51:15),node-webkit,理财产品
    国庆第五日2014-10-05 10:03,电子书
    truffle框架快速开发合约步骤
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781868.html
Copyright © 2011-2022 走看看