题目描述
class Solution { public: bool scanUInt(char *string, int &idx)//匹配无符号整型 { int tmp=idx; while(string[idx]>=‘0‘ && string[idx]<=‘9‘)++idx; return idx>tmp; } bool scanInt(char *string, int &idx)//匹配带符号(+或-)的整型 { if(string[idx]==‘+‘ || string[idx]==‘-‘)++idx; return scanUInt(string, idx); } bool isNumeric(char* string) { if(string==NULL)return false; int idx=0; bool res=scanInt(string, idx); if(string[idx]==‘.‘) { ++idx; res=scanUInt(string, idx) || res;//小心短路运算 } if(string[idx]==‘e‘ || string[idx]==‘E‘) { ++idx; res=scanInt(string, idx) && res; } return res && string[idx]==‘\0‘; } };