题目链接:
http://codeforces.com/problemset/problem/746/B
题解:
水题,我是直接暴力模拟做的这道题目的。
代码:
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3
typedef long long ll;
const int maxn=2000+10;
char s1[maxn], s2[maxn];
int main()
{
int n;
met(s1,'\0');
met(s2,'\0');
scanf("%d",&n);
scanf("%s",s1);
if(n%2==1)
{
for(int i=n-1,j=0,k=n-1;i>0;i-=2,j++,k--)
{
s2[k]=s1[i];
s2[j]=s1[i-1];
}
s2[(n/2)]=s1[0];
}
else
{
for(int i=n-1,j=0,k=n-1;i>1;i-=2,j++,k--)
{
s2[j]=s1[i-1];
s2[k]=s1[i];
}
s2[n/2-1]=s1[0];
s2[n/2]=s1[1];
}
printf("%s\n",s2);
}
本文介绍了一个CodeForces平台上的B级别题目,通过直接使用暴力模拟的方法来解决该问题。代码中包含了完整的实现过程,适合初学者理解如何用简单的编程技巧来解决特定类型的算法挑战。
751

被折叠的 条评论
为什么被折叠?



