程序猿面试宝典递归的求解字符串长度

#include<iostream>
using namespace std;
int mystrlen(char *buf,int N)
{
	if(buf[0]==0||N==0)
	return 0;
	else if(N==1)
		return 1;
	int t=mystrlen(buf,N/2);
	if(t<N/2)
		return t;
	else 
		return (t+mystrlen(buf+N/2,(N+1)/2));
}
int main()
{   char buf[]={'a','b','c','d','e','f','','x','y','z'};
    int k;
	k=mystrlen(buf,20);
	cout<<k<<endl;
	system("pause");
	return 0;
}

原文地址:https://www.cnblogs.com/mengfanrong/p/5324075.html