百度校招笔试题
来源:互联网 发布:windows双系统切换 编辑:程序博客网 时间:2024/04/29 19:54
查找得到一个字符串中最长的数字串,并返回该数字串的长度。
编写一段程序实现该函数,实现返回一个以“\\0”结束的字符串中最长的数字串的长度,并把该数字子
串的首地址赋给outputstr。不能使用任何库函数或已经存在的函数,如strlen。
例如:在字符串“abc123abcdef12345abcdefgh123456789”中,把该字符串的首地址赋给inputstr,
返回9,outputstr指向字符串“123456789”的首地址。
int maxContinuNum(const char *inputstr,char *outputstr){//int len = strlen(inputstr);if(inputstr==NULL)return NULL;int count = 0,max = 0;char *tmp_ptr; //保存数字串首地址string tmpstr, outstr; //tmpstr记录每个数字串,outstr用来保存当前最长数字串int i = 0;while(inputstr[i]!='\0'){char c = inputstr[i];int a = c-'0';if(a>=0&&a<=9){if(count==0)tmpstr = "";count++;tmpstr += c;}else{if(count>max) //如果当前数字串更长,更新outstr{outstr = "";max = count;outstr = tmpstr;}count = 0;}i++;}if(count>max){outstr = "";max = count;outstr = tmpstr;}//把得到的最长数字串复制给outputstrfor(int i=0;i<max;i++){outputstr[i] = outstr[i];}outputstr[max] = '\0';return max;}int main(){char ss[] = "abc123hdfg123456lkjiuyt123456789";char outputstr[100] = "";int max = maxContinuNum(ss,outputstr);cout<<max<<endl;int len = strlen(outputstr);for(int i=0;i<len;i++)cout<<outputstr[i]<<endl;return 0;}
0 0
- 百度校招笔试题
- 百度校招笔试题
- 一道百度2014校招笔试题
- 百度2014校招笔试题
- 2014百度校招笔试题
- 百度2014校招一道笔试题
- 2013百度校招笔试题
- 2013百度校招笔试题
- 一道百度校招笔试题
- 2014百度校招笔试题
- 2014百度校招笔试题
- 百度2012校招笔试题分析
- 百度校招研发工程师笔试题
- 2017百度校招笔试第一题
- 【2014校招】百度笔试
- 2014百度校招笔试
- 百度2015校招笔试
- 百度校招2018笔试题第三题
- iOS网络数据请求
- 弹出框
- Merge Two Sorted Lists
- raywenderlich.com的Swift编程风格指南
- 算法的时间复杂度和空间复杂度
- 百度校招笔试题
- UVA - 10562 Undraw the Trees
- toms sko salg hjatum:f
- java使用递归算法实现加载本地磁盘的文件目录和文件
- toms sko salg xuvbbt:q
- 深入理解java虚拟机(四)垃圾收集算法及HotSpot实现
- Louis Vuitton iPhone 5 Case duqmfb:w
- 海螺沟旅游攻略之探寻燕子沟
- 正则表达式批量替拘