1. 程式人生 > >Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) A Right-Left Cipher

Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) A Right-Left Cipher

題目:Right-Left Cipher

思路:直接模擬就可以了。相當於先輸出中間的字元,然後往右一個,再往左兩個,再往右三個這樣子跳著輸出。

程式碼:

#include<bits/stdc++.h>
using namespace std;

#define read(x) scanf("%d",&x)
#define maxn 100

char a[maxn+5];

int main() {
	scanf("%s",a+1);
	int n=strlen(a+1);
	
	int p=n/2+(n%2),q=1;
	for(int i=1;i<=
n;i++) { printf("%c",a[p]); p=p+q*i,q=-q; } return 0; }