可能是 char 数组没办法真正清空的问题?
#include <bits/stdc++.h>
using namespace std;
#define SMAX 10000
// #define SMAX 1048576+10
int T, cnt;
char S[SMAX], A[SMAX/2], B[SMAX/2], C[SMAX/2];
int main()
{
cin>>T;
for(int i = 0; i < T; i++)
{
// cout<<"[Debug] =====Begining====="<<endl;
// cout<<"[Debug] "<<"i = "<<i<<endl;
// S = {'\0'};
// A = {'\0'};
// B = {'\0'};
// C = {'\0'};
// memset(S, '\0', sizeof(S));
// memset(A, '\0', sizeof(A));
// memset(B, '\0', sizeof(B));
// memset(C, '\0', sizeof(C));
cnt = 0;
cin>>S;
int lenS = strlen(S);
// cout<<"[Debug] S = \""<<S<<"\" lenS = "<<lenS<<endl;
A[0] = S[0]; //以S的第一位赋给A作为初值(因为A一定是S的前缀)
C[0] = S[lenS - 1]; //以S的最后一位赋给C作为初值(因为C一定是S的后缀)
// cout<<"[Debug]"<<" <PRESET>A="<<A<<endl;
// cout<<"[Debug]"<<" <PRESET>C="<<C<<endl;
for(int a = 1; a < lenS; a++) //枚举A从左取S的长度
{
int aa;
for(aa = 0; aa < a; aa++)//因为A和S都是从0开始就无须再使用一个变量来控制A的下标了
{
A[aa] = S[aa];
// cout<<"[Debug] ===Copy Begin==="<<endl;
// cout<<"[Debug]"<<" <Copy> A["<<aa<<"] = S["<<aa<<"]"<<endl;
}
for(int b = 1; b < lenS - a; b++) //枚举B在A后取S的长度
{
int cpytmp = 0;
int bb;
for(bb = a; bb < a + b; bb++) //根据枚举的长度复制,因为复制的长度是递增的所以无需清空数组来避免之前复制的影响到后面的判断
{
B[cpytmp++] = S[bb];
// cout<<"[Debug] ===Copy Begin==="<<endl;
// cout<<"[Debug]"<<" <Copy> B["<<cpytmp - 1<<"] = S["<<bb<<"]"<<endl;
}
for(int c = 1; c < lenS - a - b; c++) //枚举C从右取S的长度
{
int ccpytmp = 0;
for(int cc = b; cc < c; cc++) //呸为什么要反过来复制 我脑子秀逗了
{
C[ccpytmp++] = S[cc];
// cout<<"[Debug] ===Copy Begin==="<<endl;
// cout<<"[Debug]"<<" <Copy> C["<<ccpytmp - 1<<"] = S["<<cc<<"]"<<endl;
}
char TMP[SMAX/2], TMP_[SMAX/2];
while(strlen(TMP) < lenS)
{
if(strcmp(strcat(strcpy(TMP_,strcat(strcat(TMP,A),strcat(TMP,B))),C),S))
{
cnt++;
// cout<<"[Debug]"<<" TMP="<<TMP<<endl;
// cout<<"[Debug]"<<" A="<<A<<endl;
// cout<<"[Debug]"<<" B="<<B<<endl;
// cout<<"[Debug]"<<" C="<<C<<endl;
}
else
{
// cout<<"[Debug] 不匹配,TMP="<<TMP<<" TMP_="<<TMP_<<endl;
}
}
}
}
}
cout<<cnt<<endl;
}
return 0;
}