求助
查看原帖
求助
1071380
baba666666楼主2024/1/19 11:17

为什么有4个紫色啊!有没有大佬解答一下,困扰好几天了。

#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;
#pragma warning(disable:4996);

void you(char* s1, long long int x1)
{
    long long int len = strlen(s1);
    char* tp = (char*)malloc(sizeof(char) * x1);
    strncpy(tp, s1 + len - x1, x1);
    memmove(s1 + x1, s1, len - x1);
    strncpy(s1, tp, x1);
    free(tp);
}

void zuo(char* s1, long long int x1)
{
    long long int len = strlen(s1);
    char* tp = (char*)malloc(sizeof(char) * x1);
    strncpy(tp, s1, x1);
    memmove(s1, s1 + x1, len - x1);
    strncpy(s1 + len - x1, tp, x1);
    free(tp);
}

void fan(char* s1)
{
    long long int len = strlen(s1);
    for (int i = 0; i < len / 2; i++)
    {
        char tp = s1[i];
        s1[i] = s1[len - i - 1];
        s1[len - i - 1] = tp;
    }
} 

char s[100000005];
long long int n;
long long int ans = 0, zj = 0;

int main(void)
{
    cin >> s;
    cin >> n;
    long long int len1 = strlen(s);
    for (int i = 0; i < n; i++)
    {
        long long int x;
        char a[10];
        cin >> a;
        if (strcmp(a, ">") == 0)
        {
            cin >> x;
            if (ans % 2 == 0) zj += x;
            else zj -= x;

        }
        else if (strcmp(a, "<") == 0)
        {
            cin >> x;
            if (ans % 2 == 1) zj += x;
            else zj -= x;
        }
        else if (strcmp(a, "rev") == 0)
        {
            ans++;
        }
        zj = zj % len1;
    }

    if (zj > 0) you(s, zj % len1);
    else zuo(s, zj % len1);
    if (ans % 2 == 1) fan(s);
    printf("%s", s);
    return 0;
}
2024/1/19 11:17
加载中...