ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

PO92反转字符串

2021-09-15 05:01:50  阅读:23  来源: 互联网

标签:right arrc int 反转 ++ length str 字符串 PO92


image

思路:无脑反转就行

#include <math.h>
#include <string>
using namespace std;

int main()
{
    Solution solution;
    string str;
    cin >> str;
    int k;
    cin >> k;
    int length = str.length();
    int num = ceil(length / k);
    char arrc[length];
    //string->char[]
    for (int i = 0; i < length; i++)
    {
        arrc[i] = str[i];
    }
    for (int i = 0; i < num; i++)
    {
        if (i % 2 == 0)
        {
            for (int left = i * k, right = (i + 1) * k - 1; left < right; ++left, --right)
            {
                swap(arrc[left], arrc[right]);
            }
        }
    }
    for (int i = 0; i < length; i++)
    {
        cout << arrc[i];
    }
    return 0;
}

标签:right,arrc,int,反转,++,length,str,字符串,PO92
来源: https://www.cnblogs.com/aoke2002/p/15270532.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有