PO92反转字符串

PO92反转字符串

思路:无脑反转就行

#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;
}

PO92反转字符串

上一篇:JUC(高并发)


下一篇:Flink-Window