不使用任何辅助变量实现strlen(递归实现strlen)
2013-04-23 20:49
423 查看
/****************************************************** 不允许调用库函数,也不允许使用任何全局或局部变量编写 int strlen(char *strDest) ******************************************************/ #include<iostream> #include<time.h> #include<cstring> using namespace std; int mystrlen(char *str) { return *(str++) ? mystrlen(str) + 1 : 0; } int main() { char a[] = "If you don't take the time to attract a woman first,\ you won't give her a reason to want to even have a conversation with you."; unsigned long start,stop; start=time(NULL); //取值为秒 cout<<a<<endl; stop=time(NULL); cout<<"running time : "<<stop-start<<endl; start=time(NULL); //取值为秒 cout<<"mystrlen(a)= "<<mystrlen(a)<<endl; stop=time(NULL); cout<<"running time : "<<stop-start<<endl; cout<<"strlen(a)= "<<strlen(a)<<endl; } /****************** If you don't take the time to attract a woman first, you won't give her a re ason to want to even have a conversation with you. running time : 0 mystrlen(a)= 130 running time : 0 strlen(a)= 130 Process returned 0 (0x0) execution time : 0.919 s Press any key to continue. ********************
相关文章推荐
- 不能使用任何库函数,不能定义任何变量实现strlen和strrev
- 不使用任何中间变量实现strlen
- 不使用任何中间变量实现strlen
- C/C++面试之算法系列--借刀杀人,不使用任何中间变量实现strlen
- C++不使用变量求字符串长度strlen函数的实现方法
- 借刀杀人,不使用任何中间变量实现strlen
- 借刀杀人,不使用任何中间变量实现strlen
- java 用递归实现:输入一个整数,用字符串逆序输出,例如输入123,输出321 ,不使用全局变量
- 不用任何变量实现strlen()函数
- 不使用任何变量编写是strlen函数(递归)
- 递归和非递归(创建变量)实现strlen
- 不使用任何中间变量实现strlen
- 数组的归并排序(经典实现:使用Ο(n)的辅助空间,递归)
- 不使用任何额外变量,实现倒序字符串
- 不使用任何中间变量,实现字符串反转
- 使用70行Python代码实现一个递归下降解析器的教程
- 实现strlen的功能【不可以使用strlen函数】
- JSP页面如何访问标签中定义的变量-使用实现
- 通过PCH File文件实现全局变量的使用
- 使用递归实现全排列的算法