华为2道机试题(review)
来源:互联网 发布:土鳖不土战斗力五 知乎 编辑:程序博客网 时间:2024/04/30 06:56
华为2道机试题:
review:
/**@date:2011/09/02 review (not to use the fun atoi())@author:weedge*/#include <stdio.h>#include <stdlib.h>void take_num(const char *strIn, int *n, unsigned int *outArray){if(strIn == NULL){printf("this is null string.");}else{int i = 0;while(*strIn){if(*strIn >= '0' && *strIn <='9'){outArray[i] = 0;while(*strIn >= '0' && *strIn <='9'){outArray[i] = outArray[i]*10 + ((*strIn++) - '0');}i++;}strIn++;}*n = i;}}void take_num1(const char *strIn, int *n, unsigned int *outArray){ //use atoi()if(strIn == NULL){ printf("this is null string."); }else{ int i = 0; while(*strIn){ if(*strIn >= '0' && *strIn <='9'){ const char *begstr = strIn; while(*strIn >= '0' && *strIn <='9'){ strIn++; } outArray[i] = atoi(begstr);/*atoi() just read back the front number*/ i++; } strIn++;} *n = i; } } int main(){char *strIn = "ab00cd+123000fght456-25 3.005fgh";int n=0;unsigned int outArray[20];take_num1(strIn,&n,outArray);printf("n:%d/n",n);for(int i=0; i<n; i++){printf("outArray[%d]=%u/n",i,outArray[i]);}system("pause");return 0;}
- 华为2道机试题(review)
- 华为机试题(2)
- 华为机试题(2)
- 华为机试题【2】
- 华为机试题3道
- 华为2014机试题2
- 华为机试题记录2
- 华为机试题(3)
- 华为机试题(4)
- 华为机试题(5)
- 华为机试题(6)
- 华为机试题(7)
- 华为机试题 (1)
- 华为机试题(3)
- 华为机试题(4)
- 华为机试题(5)
- 华为机试题(6)
- 华为机试题(7)
- 在WinForm中增加查询对话框对DataGridView数据进行循环查找
- 二分查找
- DB2数据导出和导入
- vs2005调试无法命中断点问题,0x09
- loadruner报错:Step download timeout(120 seconds)的解决方法
- 华为2道机试题(review)
- (转)[第一节]Qt安装—图文并茂搭建VS2008+QT开发环境
- 相恒的第一篇技术性文章,很用心去写的工作总结
- vim插件 ctags 和 taglist 的安装和使用
- XAMPP learning
- IT人的学习方法论(全)
- flex 中弹出窗口模式的问题
- iPhone桌面快捷电话的实现原理
- 第二十三章、软件安装: RPM, SRPM 与 YUM 功能