1.給定兩個字符串夜矗,求出它們之間最長公共子串
2.輸入一個英文句子,翻轉(zhuǎn)句子中單詞的順序县忌,但是單詞中的字符順序不變
void reverse(char *pStart, char *pEnd)
{
char temp;
if (NULL == pStart || NULL == pEnd)
{
return;
}
while (pStart < pEnd)
{
temp = *pStart;
*pStart = *pEnd;
*pEnd = temp;
pStart++;
pEnd--;
}
}
/*
輸入一個英文句子,翻轉(zhuǎn)句子中單詞的順序,但是單詞內(nèi)的字符順序不變
用例:
①句子中有多個單詞败匹、一個單詞
②NULL匣距、字符串指向的內(nèi)容為空、字符串只有空格
*/
char *reverseSentence(char *pSentence)
{
if (NULL == pSentence || strlen(pSentence) <= 1)
{
return pSentence;
}
char *pStart = pSentence;
char *pEnd = pSentence + strlen(pSentence) - 1;
reverse(pStart, pEnd);
pStart = pEnd = pSentence;
while (*pStart != '\0')
{
if ((*pEnd <= 'z' && *pEnd >= 'a') ||
(*pEnd <= 'Z' && *pEnd >= 'A'))//正常單詞字符
{
pEnd++;
}
else if (pStart != pEnd)
{
reverse(pStart, pEnd-1);
if (*pEnd != '\0')
pStart = ++pEnd;
else
break;
}
else
{
pStart = ++pEnd;
}
}
return pSentence;
}