Codeforces Round #528 (Div. 2) A. Right-Left Cipher 模拟

题解

题目大意 给一个加密后的串 问原串是什么 加密规则是第一个字符在中间后面的右边一个左边一个

计算第一个的位置 然后然后两个指针模拟即可

AC代码

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
	string s;
	cin >> s;
	int l = (s.size() - 1) / 2;
	int r = l + 1;
	while (l >= 0 || r < s.size())
	{
		cout << s[l--];
		if (r < s.size())
			cout << s[r++];
	}
	cout << endl;

	return 0;
}

猜你喜欢

转载自blog.csdn.net/CaprYang/article/details/85227749
今日推荐