写到一半不想写了,今天暂且写到这,下次继续。
按照DFA进行判断。
无符号整数
无符号小数
class Solution {
public:
bool isNumber(string s) {
return work(s.c_str());
}
bool work(const char* s){
//1、忽略前置空格
while(*s==' ') s++;
if(*s=='0'){
return num0(++s);
}
else if(*s>'0' && *s<='9'){
return num(++s);
}
else if(*s=='.'){
return dot(++s);
}
else{
return false;
}
}
bool num0(const char* s){
if(*s=='X' || *s=='x'){
//16进制
return xnum(++s);
}
else if(specialNumber(s)){
//8进制
while(specialNumber(s)) s++;
if(*s=='\0') return true;
return false;
}
else
}
bool num(const char* s){
}
//16进制数字
bool xnum(const char* s){
while(xtypeNumber(s)) s++;
if(*s=='\0') return true;
return false;
}
//.开头的小数
bool dot(const char* s){
while(*s>='0' && *s<='9') s++;
if(*s=='\0') return true;
else if(*s=='F' || *s=='f'){
//F或者f后为结尾
if(*(++s)=='\0') return true;
return false;
}
return false;
}
bool specialNumber(const char* c){
if(*c>='0' && *c<'8') return true;
return false;
}
bool pureNumber(const char* c){
if(*c>='0' && *c<='9') return true;
return false;
}
bool xtypeNumber(const char* c){
if((*c>='0' && *c<='9')||(*c>='a' && *c<='f')||(*c>='A' && *c<='F')){
return true;
}
return false;
}
};