为什么在VS2022里自测用例正确,到洛谷里就全WA
题目https://www.luogu.com.cn/problem/P5734
#include<stdio.h>
#include<string.h>
int main()
{
int n = 0;
char str[101] = { 0 };
scanf("%d", &n);
getchar();
scanf("%s", str);
getchar();
char operator[100][108] = { 0 };
for (int i = 0; i < n; i++)
{
fgets(operator[i], 108, stdin);
operator[i][strcspn(operator[i], "\r")] = '\0';
operator[i][strcspn(operator[i], "\n")] = '\0';
}
for (int i = 0; i < n; i++)
{
int len = strlen(str);
int len1 = strlen(operator[i]);
int count = 2;
int j = 0, k = 0;
switch (operator[i][0])
{
case '1':
for (j = len, k = 2; j < 100 && k < len1; j++, k++)
{
str[j] = operator[i][k];
}
str[j] = '\0';
printf("%s\n", str);
break;
case '2':
while (operator[i][count]>='0'&&operator[i][count]<='9')
{
j = j * 10 + (operator[i][count] - '0');
count++;
}
count++;
while (operator[i][count] >= '0' && operator[i][count] <= '9')
{
k = k * 10 + (operator[i][count] - '0');
count++;
}
for (int b = 0; j < 100 && b < k; j++, b++)
{
str[b] = str[j];
}
str[k] = '\0';
printf("%s\n", str);
break;
case '3':
while (operator[i][count] >= '0' && operator[i][count] <= '9')
{
j = j * 10 + (operator[i][count] - '0');
count++;
}
count++;
len1 -= count;
for (; len >= j + 1; len--)
{
str[len + len1 - 1] = str[len - 1];
}
while (operator[i][count]!='\0')
{
str[j] = operator[i][count];
count++;
j++;
}
printf("%s\n", str);
break;
case '4':
len1 -= count;
if (len1 > len)
{
printf("-1\n");
continue;
}
int find = 0;
for (count = 0; count < len - len1 + 1; count++)
{
int mid = 1;
for (j = count, k = 2; j < count + len1 && k < len1 + 2; j++, k++)
{
if (str[j] != operator[i][k])
{
mid = 0;
break;
}
}
if (mid)
{
printf("%d\n", count);
find = 1;
break;
}
}
if (!find)
{
printf("-1\n");
}
break;
}
}
return 0;
}