atof函数的实现 查找最长数字子串
来源:互联网 发布:冬季男士乳液推荐知乎 编辑:程序博客网 时间:2024/05/17 04:26
atof的实现
#include <iostream>using namespace std;double my_atof(const char * str){double res = 0.0;double d = 10.0;bool flag = false;while (*str == ' '){str++;}if (*str == '-'){flag = true;str++;}if (!(*str <= '9') || !(*str >= '0')){cout << "非数字串" << endl;}while (*str <= '9' && *str >= '0' && *str != '.'){res = res * 10 + (*str) - '0';str++;}if (*str == '\0')return res * (flag ? -1.0 : 1.0);if (*str == '.'){str++;}while (*str <= '9' && *str >= '0' && *str != '\0'){res = res + ((*str) - '0') / d;d *= 10.0;str++;}return res * (flag ? -1.0 : 1.0);}int main(){char *test1 = " -123.342";cout << my_atof(test1) << endl;system("pause");return 0;}查找最长数字子串
#include <iostream>using namespace std;int maxContinueNumber(const char * src, char * dst){int start = 0;int end = 0;int max = 0;int startTmp = 0;int maxTmp = 0;int cur = 0;int length = strlen(src);char * tmp = dst;for (; cur < length; cur++){if (*(src + cur) <= '9' && *(src + cur) >= '0'){if (maxTmp == 0){startTmp = cur;}maxTmp++;}else{if (maxTmp > max){start = startTmp;end = cur;max = maxTmp;maxTmp = 0;}}}if (maxTmp > max){start = startTmp;end = cur;max = maxTmp;maxTmp = 0;}for (int i = start; i < end; i++){*dst++ = src[i];}*dst = '\0';cout << tmp << endl;return max;}int main(){char test[] = "abc123ad12345";char tmp[100] = "";cout << maxContinueNumber(test, tmp) << endl;system("pause");return 0;}
阅读全文
0 0
- atof函数的实现 查找最长数字子串
- atof函数的实现
- atof函数的实现
- 查找字符串中最长的连续数字子串
- 最长回文子串的查找
- 字符串中最长的数字子串
- C 标准库 atof 函数的实现
- 自己实现的atio()和atof()函数
- atof()函数实现
- atof & aoti 函数实现
- java 实现atof函数
- 查找两个字符串的最长公共子串的Javascript函数
- 在字符串中查找连续重复的最长子串的C++实现
- java实现获取输入字符串内最长数字子串
- 字符串查找最长子串
- C 最长数字子串
- 找最长数字子串
- 最长连续数字子串
- JQuery UI----初次学习(添加关于添加UI包的顺序与dialog属性设置)
- LightOJ 1141 Number Transformation
- Apache-CXF开发Webservice学习笔记
- 剑指offer-- 合并两个排序的链表
- Linux 防火墙iptables (五)用iptables为公司配置防火墙实例(实战)
- atof函数的实现 查找最长数字子串
- vue项目开发第二篇之新建vue项目
- js输出菱形
- -webkit-text-fill-color
- 如何打开IIS
- html转pdf。。。
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Stack trace: ExitCodeException exitCode=1:
- 基于单链表和环形队列的生产者-消费者模型