比较经典的题目,剑指offer上也有,各种面试笔试宝典上也都有
好像也不算太难,核心的代码只有几行,但是往往需要我们重点考虑的其实是在各种特殊输入的考虑上。
#include <iostream>
#include <cstdio>
using namespace std;
float atof(const char * arr)
{
const char * index = arr;
float result = 0;
int fcount = 0;
int Sign = 1;
bool HavePoint = false;
while(' ' == *index)
{
index++;
}
if ('-' == *index)
{
Sign = -1;
index++;
}
if ('+' == *index)
{
index++;
}
while(*index != '\0')
{
if ('.' == *index)
{
HavePoint = true;
break;
}
if (*index <= '9' && *index >= '0')
{
result = (result * 10) + (*index - '0');
}
index++;
}
// cout << result << endl;
index++;
while(*