表示数值的字符串

 

class Solution {
public:
    bool isNum(char *ch)
        {
        if(*ch<='9'&&*ch>='0')
            return true;
        else return false;
    }
    bool isNumeric(char* string)
    {
        if(string==NULL)
            return false;
        if(*string=='+'||*string=='-')
            string++;
        if(*string=='\0')
                return false;
        while(*string!='\0')
            {
            if(*string=='.'||*string=='e'||*string=='E')
                 break;
             else if(isNum(string))
                 string++;
                else return false;
             
        }
        if(*string=='.')
            {
            string++;
  
            while(*string!='\0')
            {
             if(isNum(string))
                 string++;
             else if(*string=='e'||*string=='E') 
                 break;
                 else return false;
        }
        }
        if(*string=='e'||*string=='E')
            {
            string++;
            if(*string=='\0')
                return false;
            if(*string=='+'||*string=='-')
            string++;
            if(*string=='\0')
                return false;
             while(*string!='\0')
            {
                if(isNum(string))
                 string++;
                else return false;    
        }
            
        }
        return true;
    }

};

 

posted on 2016-04-29 11:58  RenewDo  阅读(146)  评论(0编辑  收藏  举报

导航