只有后两个对了,大佬求调QAQ

P5734 【深基6.例6】文字处理软件

_Yamada_Ryo @ 2024-11-27 18:37:43

#include <stdio.h>
#include <string.h>
void insert_str(char *str, const char *str2, int position)
{
    int dest_len = strlen(str);
    int src_len = strlen(str2);
    int index = 0;
    for (int i = position; i < dest_len; i++)
    {
        str[i + src_len] = str[i];
    }
    for (int i = position; i < src_len + position; i++)
    {
        str[i] = str2[index++];
    }
}
int main()
{
    char str[101];
    int T, operation;
    scanf("%d", &T);
    scanf("%s", &str);
    while (T--)
    {
        int a = 0, b = 0;
        char str2[101] = {'\0'};
        scanf("%d", &operation);

        switch (operation)
        {
        case 1:
            scanf("%s", &str2);
            strcat(str, str2);
            printf("%s\n", str);
            break;
        case 2:
            scanf("%d %d", &a, &b);
            for (int i = a; i <= a + b; i++)
            {
                str[i - a] = str[i];
            }
            for (int i = b; i < strlen(str); i++)
            {
                str[i] = '\0';
            }
            printf("%s\n", str);
            break;
        case 3:
            scanf("%d %s", &a, &str2);
            insert_str(str, str2, a);
            printf("%s\n", str);
            break;
        case 4:
            scanf("%s", &str2);
            char *result = strstr(str, str2);
            if (result != NULL)
            {
                printf("%d\n", result - str);
            }
            else
            {
                printf("-1\n");
            }
            break;
        default:
            break;
        }
    }
}

by tzl_Dedicatus545 @ 2024-11-27 18:46:16

@_Yamada_Ryo 你这么菜还配叫山田凉?


by _Yamada_Ryo @ 2024-11-27 19:01:24

@tzl_Dedicatus545QAQ波奇酱我错了,借我点钱(


|