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

来源:互联网 发布:sql do while的用法 编辑:程序博客网 时间:2024/04/30 19:30
#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','\0','x','y','z'};    int k;k=mystrlen(buf,20);cout<<k<<endl;system("pause");return 0;}

1 0
原创粉丝点击