sicily 1007

#include "iostream"
#include "string"
#include <algorithm>//使用reverse时候,这个头文件需要包含!
using namespace std;
int main()
{
 int n, length;
 string str;
 while (cin >> n )//输入columns
 {
  if (n != 0)
  {
   cin >> str;//输入字符串
   length = str.size();
   int row = length / n;//需要new的string数组的个数
   string *str1 = new string [row];
   for (int j = 0, i = 0; j < length && i < row; j++)//将字符串平均分到每一个数组
   {
    str1[i] += str[j];
    if (j !=0 && ((j + 1)% n == 0))  i++;
   }
   for (int i = 1; i < row; i = i + 2)
    reverse(str1[i].begin(), str1[i].end());//将字符串倒置
   string str2 = "";
   for (int i = 0; i < n; i++)//重新将字符串数组变为一个字符串
    for (int j = 0; j < row; j++)
    {
     str2.push_back(str1[j][i]);
    }
     cout << str2 << endl;
  }
  else break;
 }
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值