Validate if a given string is numeric.
Some examples:
"0"
=> true
" 0.1 "
=> true
"abc"
=> false
"1 a"
=> false
"2e10"
=> true
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
bool isNumber(string s) { int l = s.length(), i; bool flag=0, point[2]={ 0,0}, num[2]={ 0,0}; for(i=0; s[i] == ' '; i++); for(; i
测试用例:
"0e" -- false
". 1" -- false
"-1." -- true
".-4" -- false
"+.8" -- true
"6e6.5" -- false