資源簡介
輸入一個字符串,將輸出該字符串最長對稱子串及其長度,很精巧的算法
代碼片段和文件信息
//求對稱子字符串的最大長度
//author:ZR
#include?“stdafx.h“
#include?
#include?
using?namespace?std;
string?returnString(string?strint?iint?j){
string?returnStr=““;
if(i>j)
return?returnStr;
else{
for(int?k=i;k!=j+1;k++)
returnStr+=str[k];
}
return?returnStr;
}
//弱一點的判斷字符串對稱的函數
//這個一看就是web開發寫多了。。。注意代碼質量啊
bool?symmetryOrNot(string?str){
int?length=str.size();
for(int?i=0;i!=length/2;i++){
if(str[i]!=str[length-i-1])
return?false;
}
return?true;
}
//牛一點的判斷字符串對稱的函數
//調用方式:isSymmetrical(&str[0]&str[str.size()-1])
bool?isSymmetrical(char*?pBeginchar*?pEnd){
if(pBegin==NULL?||?pEnd==NULL?||?pBegin>pEnd)
return?false
- 上一篇:Opencv + c++實現簡單的小波變換
- 下一篇:最小二乘法曲線擬合C++
評論
共有 條評論