主题:第80次比赛代码请版主帮看
void CMinInsertDlg::OnGetC()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_A==""||m_B=="") return;
int Alengh=m_A.GetLength();
int Blengh=m_B.GetLength();
LPCTSTR pA=LPCTSTR(m_A);
LPCTSTR pB=LPCTSTR(m_B);
int i;
for (i=0;i<Alengh;i++)
{
if(pA[i]<pB[0]) continue;
else if (pA[i]>pB[0]) break;
else if (pA[i]==pB[0])
{
int j;
BOOL bmoveflag=TRUE;
BOOL bendflag=FALSE;
int end=Alengh; //end是以A为索引的
for (j=1;j<Blengh;j++)
{
int k=i+j;
if (k>=end) k=i+j%(end-i);
if (pA[k]==pB[j])
{
continue;
}
else
{
if(!bendflag)
{
if(pA[k]<pB[j]) break;
end=i+j;
j=j-1;
bendflag=TRUE;
continue;
}
if(pA[k]>pB[j])
{
bmoveflag=FALSE;
break;
}
else
{
break;
}
}
}
if (!bmoveflag) break;
}
}
m_C=m_A.Left(i)+m_B+m_A.Mid(i);
UpdateData(FALSE);
}
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_A==""||m_B=="") return;
int Alengh=m_A.GetLength();
int Blengh=m_B.GetLength();
LPCTSTR pA=LPCTSTR(m_A);
LPCTSTR pB=LPCTSTR(m_B);
int i;
for (i=0;i<Alengh;i++)
{
if(pA[i]<pB[0]) continue;
else if (pA[i]>pB[0]) break;
else if (pA[i]==pB[0])
{
int j;
BOOL bmoveflag=TRUE;
BOOL bendflag=FALSE;
int end=Alengh; //end是以A为索引的
for (j=1;j<Blengh;j++)
{
int k=i+j;
if (k>=end) k=i+j%(end-i);
if (pA[k]==pB[j])
{
continue;
}
else
{
if(!bendflag)
{
if(pA[k]<pB[j]) break;
end=i+j;
j=j-1;
bendflag=TRUE;
continue;
}
if(pA[k]>pB[j])
{
bmoveflag=FALSE;
break;
}
else
{
break;
}
}
}
if (!bmoveflag) break;
}
}
m_C=m_A.Left(i)+m_B+m_A.Mid(i);
UpdateData(FALSE);
}

您所在位置:
